[Bug] Local clone fails reporing an empty checkout as not empty
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Biên dịch repro.c bằng lệnh pkg-config được nêu, chuẩn bị các repository tạm thời và cấu hình, rồi chạy tái hiện clone cục bộ. Theo dõi đường dẫn clone cục bộ từ chối bare repository đã có nội dung, sau đó xác minh rằng việc clone thành công với thiết lập này và thêm coverage cho trường hợp được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
This error is really weird, so I’d like to start by apologizing for the odd title of this issue :(.
TL;DR libgit2 reports git_clone failed: the repository is not empty on a empty repository.
How to reproduce
First we need a helper binary using libgit2.
// repro.c
#include <git2.h>
#include <stdio.h>
#include <string.h>
static int fail(const char *what, int code) {
const git_error *error = git_error_last();
fprintf(stderr, "%s failed", what);
if (error != NULL && error->message != NULL) {
fprintf(stderr, ": %s", error->message);
} else {
fprintf(stderr, " with code %d", code);
}
fputc('\n', stderr);
return 1;
}
static int usage(void) {
fprintf(stderr, "usage:\n"
" libgit2-repro init-bare <repo>\n"
" libgit2-repro clone-local <src> <dst>\n");
return 2;
}
int main(int argc, char **argv) {
int status = 0;
git_libgit2_init();
if (argc == 3 && strcmp(argv[1], "init-bare") == 0) {
git_repository *repo = NULL;
git_repository_init_options opts;
int rc = git_repository_init_init_options(
&opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION);
if (rc != 0) {
status = fail("git_repository_init_init_options", rc);
goto done;
}
opts.flags = GIT_REPOSITORY_INIT_BARE | GIT_REPOSITORY_INIT_MKPATH;
rc = git_repository_init_ext(&repo, argv[2], &opts);
if (rc != 0) {
status = fail("git_repository_init_ext", rc);
goto done;
}
git_repository_free(repo);
} else if (argc == 4 && strcmp(argv[1], "clone-local") == 0) {
git_repository *repo = NULL;
git_clone_options opts;
int rc = git_clone_options_init(&opts, GIT_CLONE_OPTIONS_VERSION);
if (rc != 0) {
status = fail("git_clone_options_init", rc);
goto done;
}
opts.local = GIT_CLONE_LOCAL;
opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_DRY_RUN;
rc = git_clone(&repo, argv[2], argv[3], &opts);
if (rc != 0) {
status = fail("git_clone", rc);
goto done;
}
git_repository_free(repo);
} else {
status = usage();
}
done:
git_libgit2_shutdown();
return status;
}
You could compile it by:
cc -std=c11 $(pkg-config --cflags libgit2) -o libgit2-repro repro.c $(pkg-config --libs libgit2)
Then, initialize the environment:
work="$(mktemp -d /tmp/repro-XXXXXX)"
mkdir "$work/home"
export HOME="$work/home" # create a fake home so that this would not break your env :)
export GIT_CONFIG_NOSYSTEM=1
And the following two files:
// $HOME/.gitconfig
[includeIf "gitdir:/"]
path = ~/other.gitconfig
// $HOME/other.gitconfig
[init]
defaultBranch = main
[user]
email = test@example.com
name = test
Then, we could create the repositories:
$ git init "$work/src"
$ printf "hello\n" > "$work/src/README.md"
$ git -C "$work/src" add README.md
$ git -C "$work/src" commit -m initial
[main (root-commit) b80a053] initial
1 file changed, 1 insertion(+)
create mode 100644 README.md
$ cat "$work/src/.git/HEAD"
ref: refs/heads/main
$ ./libgit2-repro init-bare "$work/db.git"
$ cat "$work/db.git/HEAD"
ref: refs/heads/master
$ git --git-dir="$work/db.git" fetch "$work/src" '+refs/heads/*:refs/remotes/origin/*' '+HEAD:refs/remotes/origin/HEAD'
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (3/3), 187 bytes | 187.00 KiB/s, done.
From tmp/src
* [new branch] main -> origin/main
* [new ref] HEAD -> origin/HEAD
$ ./libgit2-repro clone-local "$work/db.git" "$work/checkout"
git_clone failed: the repository is not empty
- Ngôn ngữ chính
- C
- Star
- 10.6k
- Fork
- 2.7k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của libgit2/libgit2
-
hashsig: the similarity heap evicts but never inserts, so the retained set is not the extremes Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Tất cả issue của libgit2/libgit2
Issue tương tự
-
internal.h中,漏掉了1个定义。 Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Broadcast Documentation Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
kovidgoyal/kitty#10516 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
zephyrproject-rtos/zephyr#120011 ·