在 `core.symlinks=false` 且索引中包含符号链条条目时,checkout 会出现幻影 `GIT_ECONFLICT` — 状态报告工作目录已清理,SAFE checkout 会以 "N 个冲突阻止 checkout" 来拒绝 checkout
作者: liz7up创建于 2026年9月3日更新于 2026年9月3日
/* gcc -o repro repro.c -I <libgit2.a> -lpthread -lrt
- prints: workdir status entries: 0 (clean)
SAFE checkout B: rc=-13 message="1 conflict prevents checkout"
*/ #include <git2.h> #include <stdio.h> #include <string.h> #include <stdlib.h>
static void die(const char* what, int rc) { const git_error* e = git_error_last(); fprintf(stderr, "%s failed rc=%d: %s\n", what, rc, e && e->message ? e->message : "?"); exit(1); }
int main(int argc, char** argv) { if (argc < 2) { fprintf(stderr, "usage: %s \n", argv[0]); return 2; } git_libgit2_init(); const char* dir = argv[1];
git_repository* repo = NULL;
if (git_repository_init(&repo, dir, 0) != 0) die("init", -1);
git_config* cfg = NULL;
if (git_repository_config(&cfg, repo) != 0) die("config", -1);
git_config_set_bool(cfg, "core.symlinks", 0); /* sandbox w/o symlink support */
git_config_set_bool(cfg, "core.filemode", 1); /* linux-style default */
git_config_free(cfg);
git_signature* sig = NULL;
if (git_signature_new(&sig, "t", "t@t", 1234567890, 0) != 0) die("sig", -1);
/* commit A: Claude.md (regular) + AGENTS.md (symlink -> Claude.md) */
git_index* index = NULL;
if (git_repository_index(&index, repo) != 0) die("index", -1);
git_oid blobClaude, blobLink, treeA, treeB, commitA, commitB;
if (git_blob_create_from_buffer(&blobClaude, repo, "hello\n", 6) != 0) die("blob1", -1);
if (git_blob_create_from_buffer(&blobLink, repo, "Claude.md", 9) != 0) die("blob2", -1);
git_index_entry e = {0};
e.mode = GIT_FILEMODE_BLOB; e.id = blobClaude; e.path = "Claude.md";
if (git_index_add(index, &e) != 0) die("add1", -1);
memset(&e, 0, sizeof(e));
e.mode = GIT_FILEMODE_LINK; e.id = blobLink; e.path =
…
内容来源: libgit2/libgit2