{"thread":{"id":"66977","subject":"[PATCH] clone: pass work tree to repack child of --dissociate","startedAt":"2026-12-02T20:45:40Z","lastAt":"2026-12-02T20:45:40Z","messageCount":1,"participants":["Daniel Fox via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559911","messageId":"pull.2346.git.1796244340074.gitgitgadget@gmail.com","threadId":"66977","inReplyTo":null,"subject":"[PATCH] clone: pass work tree to repack child of --dissociate","fromName":"Daniel Fox via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-12-02T20:45:40Z","receivedAt":"2026-12-02T20:45:40Z","isPatch":true,"sender":{"key":"name:Daniel Fox","avatar":null},"body":"From: Daniel Fox <danudey@me.com>\n\nAfter \"git clone --dissociate\" copies the borrowed objects,\ndissociate_from_references() runs \"git repack -a -d\" in a child\nprocess. init_db() exports GIT_DIR, so the child inherits it.\nGIT_WORK_TREE is not exported. With GIT_DIR set and no\nGIT_WORK_TREE, the child treats its current directory as the top of\nthe work tree. That directory is the one clone was run from, which\nis usually the parent of the new work tree.\n\nRepack itself does not care about the work tree, but it reads the\nindex. When core.fsmonitor is enabled, reading the index can start\nthe fsmonitor daemon implicitly. That daemon then watches the wrong\ndirectory and never sees the cookie files that clients create in\nthe real work tree. As a result, every fsmonitor query in the new\nclone waits for the cookie timeout.\n\nWhen we have a work tree, export it to the child as GIT_WORK_TREE.\n\nSigned-off-by: Daniel Fox <danudey@me.com>\n---\n    clone: pass work tree to repack child of --dissociate\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2346%2Fdanudey%2Ffsmonitor-clone-dissociate-worktree-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2346/danudey/fsmonitor-clone-dissociate-worktree-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2346\n\n builtin/clone.c              | 11 +++++++++++\n t/t7527-builtin-fsmonitor.sh | 24 ++++++++++++++++++++++++\n 2 files changed, 35 insertions(+)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex ac40250d25..f10f95e017 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -851,6 +851,17 @@ static void dissociate_from_references(void)\n \n \t\tcmd.git_cmd = 1;\n \t\tcmd.no_stdin = 1;\n+\t\t/*\n+\t\t * We export GIT_DIR but not GIT_WORK_TREE, so without this\n+\t\t * the child would treat our cwd (the parent of the new\n+\t\t * work tree) as its work tree.  That matters because\n+\t\t * \"repack\" reads the index, which can auto-start the\n+\t\t * fsmonitor daemon, and it would then watch the wrong\n+\t\t * directory.\n+\t\t */\n+\t\tif (the_repository->worktree)\n+\t\t\tstrvec_pushf(&cmd.env, \"%s=%s\", GIT_WORK_TREE_ENVIRONMENT,\n+\t\t\t\t     the_repository->worktree);\n \t\tstrvec_pushl(&cmd.args, \"repack\", \"-a\", \"-d\", NULL);\n \t\tif (run_command(&cmd))\n \t\t\tdie(_(\"cannot repack to clean up\"));\ndiff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh\nindex 86195770e9..a49511945b 100755\n--- a/t/t7527-builtin-fsmonitor.sh\n+++ b/t/t7527-builtin-fsmonitor.sh\n@@ -304,6 +304,30 @@ test_expect_success MINGW,SHORTNAMES 'implicit daemon stop (rename GIT~2)' '\n \tverify_implicit_shutdown test_implicit_1s2\n '\n \n+test_expect_success 'clone --dissociate starts daemon on the new work tree' '\n+\ttest_when_finished \"stop_daemon_delete_repo dissociate/clone; rm -rf dissociate dissociate.trace\" &&\n+\n+\tgit init dissociate/src &&\n+\ttest_commit -C dissociate/src file &&\n+\tgit clone dissociate/src dissociate/ref &&\n+\n+\t# \"--dissociate\" runs \"git repack\" in a child process, which\n+\t# reads the index and so implicitly starts the daemon.  That\n+\t# daemon must watch the new work tree, not the directory clone\n+\t# was run from; otherwise it never sees its own cookie files\n+\t# and every query waits for the cookie timeout.\n+\t(\n+\t\tcd dissociate &&\n+\t\tGIT_TRACE_FSMONITOR=\"$TRASH_DIRECTORY/dissociate.trace\" &&\n+\t\texport GIT_TRACE_FSMONITOR &&\n+\t\tgit -c core.fsmonitor=true clone --reference ref --dissociate \\\n+\t\t\t\"file://$TRASH_DIRECTORY/dissociate/src\" clone &&\n+\t\tgit -C clone fsmonitor--daemon status &&\n+\t\ttest-tool -C clone fsmonitor-client query --token 0 >/dev/null\n+\t) &&\n+\ttest_grep ! \"cookie_wait timed out\" dissociate.trace\n+'\n+\n test_expect_success 'cannot start multiple daemons' '\n \ttest_when_finished \"stop_daemon_delete_repo test_multiple\" &&\n \n\nbase-commit: 03b41523c576f26ad34085378717a0c1b287470f\n-- \ngitgitgadget\n\n"}]}