All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel Fox via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Daniel Fox <danudey@me.com>, Daniel Fox <danudey@me.com>
Subject: [PATCH] clone: pass work tree to repack child of --dissociate
Date: Wed, 02 Dec 2026 20:45:40 +0000	[thread overview]
Message-ID: <pull.2346.git.1796244340074.gitgitgadget@gmail.com> (raw)

From: Daniel Fox <danudey@me.com>

After "git clone --dissociate" copies the borrowed objects,
dissociate_from_references() runs "git repack -a -d" in a child
process. init_db() exports GIT_DIR, so the child inherits it.
GIT_WORK_TREE is not exported. With GIT_DIR set and no
GIT_WORK_TREE, the child treats its current directory as the top of
the work tree. That directory is the one clone was run from, which
is usually the parent of the new work tree.

Repack itself does not care about the work tree, but it reads the
index. When core.fsmonitor is enabled, reading the index can start
the fsmonitor daemon implicitly. That daemon then watches the wrong
directory and never sees the cookie files that clients create in
the real work tree. As a result, every fsmonitor query in the new
clone waits for the cookie timeout.

When we have a work tree, export it to the child as GIT_WORK_TREE.

Signed-off-by: Daniel Fox <danudey@me.com>
---
    clone: pass work tree to repack child of --dissociate

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2346%2Fdanudey%2Ffsmonitor-clone-dissociate-worktree-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2346/danudey/fsmonitor-clone-dissociate-worktree-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2346

 builtin/clone.c              | 11 +++++++++++
 t/t7527-builtin-fsmonitor.sh | 24 ++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/builtin/clone.c b/builtin/clone.c
index ac40250d25..f10f95e017 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -851,6 +851,17 @@ static void dissociate_from_references(void)
 
 		cmd.git_cmd = 1;
 		cmd.no_stdin = 1;
+		/*
+		 * We export GIT_DIR but not GIT_WORK_TREE, so without this
+		 * the child would treat our cwd (the parent of the new
+		 * work tree) as its work tree.  That matters because
+		 * "repack" reads the index, which can auto-start the
+		 * fsmonitor daemon, and it would then watch the wrong
+		 * directory.
+		 */
+		if (the_repository->worktree)
+			strvec_pushf(&cmd.env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT,
+				     the_repository->worktree);
 		strvec_pushl(&cmd.args, "repack", "-a", "-d", NULL);
 		if (run_command(&cmd))
 			die(_("cannot repack to clean up"));
diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh
index 86195770e9..a49511945b 100755
--- a/t/t7527-builtin-fsmonitor.sh
+++ b/t/t7527-builtin-fsmonitor.sh
@@ -304,6 +304,30 @@ test_expect_success MINGW,SHORTNAMES 'implicit daemon stop (rename GIT~2)' '
 	verify_implicit_shutdown test_implicit_1s2
 '
 
+test_expect_success 'clone --dissociate starts daemon on the new work tree' '
+	test_when_finished "stop_daemon_delete_repo dissociate/clone; rm -rf dissociate dissociate.trace" &&
+
+	git init dissociate/src &&
+	test_commit -C dissociate/src file &&
+	git clone dissociate/src dissociate/ref &&
+
+	# "--dissociate" runs "git repack" in a child process, which
+	# reads the index and so implicitly starts the daemon.  That
+	# daemon must watch the new work tree, not the directory clone
+	# was run from; otherwise it never sees its own cookie files
+	# and every query waits for the cookie timeout.
+	(
+		cd dissociate &&
+		GIT_TRACE_FSMONITOR="$TRASH_DIRECTORY/dissociate.trace" &&
+		export GIT_TRACE_FSMONITOR &&
+		git -c core.fsmonitor=true clone --reference ref --dissociate \
+			"file://$TRASH_DIRECTORY/dissociate/src" clone &&
+		git -C clone fsmonitor--daemon status &&
+		test-tool -C clone fsmonitor-client query --token 0 >/dev/null
+	) &&
+	test_grep ! "cookie_wait timed out" dissociate.trace
+'
+
 test_expect_success 'cannot start multiple daemons' '
 	test_when_finished "stop_daemon_delete_repo test_multiple" &&
 

base-commit: 03b41523c576f26ad34085378717a0c1b287470f
-- 
gitgitgadget

                 reply	other threads:[~2026-12-02 20:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.2346.git.1796244340074.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=danudey@me.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.