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

[PATCH] builtins: reset startup_info->have_run_setup_gitdir when unsetting up repository

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 27, 2010, 09:13 UTC
Message-ID
<1269681184-1992-2-git-send-email-pclouds@gmail.com>
In-Reply-To
<1269681184-1992-1-git-send-email-pclouds@gmail.com>

startup_info->have_run_setup_gitdir is used to guard unallowed access to repository. When a repository has been set up and the real command does not expect any setup, we should revert to the original "fresh" state, including startup_info->have_run_setup_gitdir. Otherwise, the next attempt to set up repository will fail.

While at it, also reset repository_format_version to zero. When omitted, the format should be understood as the last supported version, i.e. zero. This is probably only used by "git init" or "git clone".

Fault caught by Jonathan Nieder (and demonstrated with a beautiful test case)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Junio, I can split this up and put it to the original patches where the faults
 are introduced if you want.
 git.c           |   13 ++++++++-----
 setup.c         |    2 +-
 t/t0001-init.sh |   14 ++++++++++++++
 3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/git.c b/git.c
index 7ebfea5..5c249fd 100644
--- a/git.c
+++ b/git.c
@@ -242,11 +242,14 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 			int nongit_ok;
 			setup_git_directory_gently(&nongit_ok);
 		}
-		else if (startup_info->have_repository) {
-			if (p->option & (RUN_SETUP_GENTLY | RUN_SETUP))
-				; /* done already */
-			else
-				unset_git_directory(startup_info->prefix);
+		else if (startup_info->have_run_setup_gitdir) {
+			if (startup_info->have_repository) {
+				if (p->option & (RUN_SETUP_GENTLY | RUN_SETUP))
+					; /* done already */
+				else
+					unset_git_directory(startup_info->prefix);
+			}
+			startup_info->have_run_setup_gitdir = 0;
 		}
 
 		if (use_pager == -1 && p->option & RUN_SETUP)
diff --git a/setup.c b/setup.c
index d9bb616..43b529e 100644
--- a/setup.c
+++ b/setup.c
@@ -358,7 +358,7 @@ void unset_git_directory(const char *prefix)
 	inside_git_dir = -1;
 
 	/* Initialized in check_repository_format_version() */
-	repository_format_version = 0xFF;
+	repository_format_version = 0;
 	shared_repository = PERM_UMASK;
 	is_bare_repository_cfg = -1;
 	git_work_tree_cfg = NULL;
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 5386504..f93856b 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -33,6 +33,20 @@ test_expect_success 'plain' '
 	check_config plain/.git false unset
 '
 
+test_expect_success 'plain through aliased command' '
+	(
+		unset GIT_DIR GIT_WORK_TREE GIT_CONFIG_NOGLOBAL &&
+		HOME=$(pwd)/alias-config &&
+		export HOME &&
+		mkdir alias-config &&
+		echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
+		mkdir plain-aliased &&
+		cd plain-aliased &&
+		git aliasedinit
+	) &&
+	check_config plain-aliased/.git false unset
+'
+
 test_expect_success 'plain with GIT_WORK_TREE' '
 	if (
 		unset GIT_DIR
-- 
1.7.0.rc1.541.g2da82.dirty
Previous: Nguyễn Thái Ngọc DuyNext: Jonathan Nieder
Message 2 of 5 in “builtins: setup repository before print unknown command error”
  1. builtins: setup repository before print unknown command errorNguyễn Thái Ngọc Duy, Mar 27, 2010
  2. builtins: reset startup_info->have_run_setup_gitdir when unsetting up repositoryNguyễn Thái Ngọc Duy, Mar 27, 2010
  3. Jonathan NiederMar 27, 2010
  4. Nguyen Thai Ngoc DuyMar 28, 2010
  5. Jonathan NiederMar 28, 2010

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.