git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: core.worktree bug

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Dec 15, 2009, 16:30 UTC
Message-ID
<20091215163042.GA14810@do>
In-Reply-To
<200912071115.48085.robin.rosenberg.lists@dewire.com>
On Mon, Dec 07, 2009 at 11:15:47AM +0100, Robin Rosenberg wrote:
Show 14 quoted lines
> $ git config core.worktree $(cd ../r1;pwd)
> $ git status
> # On branch master
> # Changed but not updated:
> #   (use "git add/rm <file>..." to update what will be committed)
> #   (use "git checkout -- <file>..." to discard changes in working directory)
> #
> #       deleted:    f
> #
> no changes added to commit (use "git add" and/or "git commit -a")
> 
> => Seems the config is actually honored even though GIT_DIR is not set.
> 
> Bisect tells me 4f38f6b5bafb1f7f85c7b54d0bb0a0e977cd947c broke it. My main point is that I am
You should have CCed me.
> implementing this in JGit so I want the same behaviour. Question: Should we try to fix this
> in git so it matches the documentation or fix the documentation to match behaviour.
> 
> The breakage appeared over a year ago and no one has complained.

This is, I think, due to the shared use of git_work_tree_cfg. When setup_git_directory_gently() comes close to the end, work_tree has been detected and set. Then check_repository_format_gently() is called to make sure the repository is valid. Among the checks are core.worktree check, which overrides the previously-set git_work_tree_cfg.

This might be the fix, or a start of new breakages. I'll need to look at this again and make a proper patch message with tests if it's really correct.

diff --git a/setup.c b/setup.c
index f67250b..1385edb 100644
--- a/setup.c
+++ b/setup.c
@@ -280,6 +280,18 @@ const char *read_gitfile_gently(const char *path)
 	return path;
 }
 
+static int check_repository_work_tree(const char *var, const char *value, void *cb)
+{
+	if (strcmp(var, "core.worktree") == 0) {
+		if (!value)
+			return config_error_nonbool(var);
+		free(git_work_tree_cfg);
+		git_work_tree_cfg = xstrdup(value);
+		inside_work_tree = -1;
+	}
+	return 0;
+}
+
 /*
  * We cannot decide in this function whether we are in the work tree or
  * not, since the config can only be read _after_ this function was called.
@@ -317,6 +329,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			if (!work_tree_env) {
 				retval = set_work_tree(gitdirenv);
 				/* config may override worktree */
+				git_config(check_repository_work_tree, NULL);
 				if (check_repository_format_gently(nongit_ok))
 					return NULL;
 				return retval;
@@ -394,6 +407,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			die_errno("Cannot change to '%s/..'", cwd);
 	}
 
+	git_config(check_repository_work_tree, NULL);
 	inside_git_dir = 0;
 	if (!work_tree_env)
 		inside_work_tree = 1;
@@ -471,12 +485,6 @@ int check_repository_format_version(const char *var, const char *value, void *cb
 		is_bare_repository_cfg = git_config_bool(var, value);
 		if (is_bare_repository_cfg == 1)
 			inside_work_tree = -1;
-	} else if (strcmp(var, "core.worktree") == 0) {
-		if (!value)
-			return config_error_nonbool(var);
-		free(git_work_tree_cfg);
-		git_work_tree_cfg = xstrdup(value);
-		inside_work_tree = -1;
 	}
 	return 0;
 }
-- 
Duy
Previous: Robin RosenbergNext: Nguyễn Thái Ngọc Duy
Message 2 of 11 in “core.worktree bug”
  1. Robin RosenbergDec 7, 2009
  2. Nguyen Thai Ngoc DuyDec 15, 2009
  3. Fix core.worktree being used when GIT_DIR is not setNguyễn Thái Ngọc Duy, Dec 27, 2009
  4. Junio C HamanoDec 27, 2009
  5. Robin RosenbergDec 28, 2009
  6. Nguyen Thai Ngoc DuyDec 28, 2009
  7. Documentation: always respect core.worktree if setNguyễn Thái Ngọc Duy, Dec 28, 2009
  8. Junio C HamanoDec 28, 2009
  9. Documentation: always respect core.worktree if setNguyễn Thái Ngọc Duy, Dec 29, 2009
  10. Junio C HamanoDec 29, 2009
  11. Robin RosenbergDec 29, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.