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

[PATCH 2/2] builtins: setup repository before print unknown command error

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

help_unknown_cmd() will need to look into repository's config, in order to collect all possible commands/aliases and give a suggestion. So, repository must be set up before this function is called.

As it is now, because
 - alias handling will always be done before help_unknown_cmd()
 - alias handling code will search and set up repository if found
 - alias handline code will not undo repository setup

These ensure that repository will always be set up (or attempted to set up) before help_unknown_cmd(), so there is no issue. But the setup dependency here is subtle. It may break some day if someone reorders the loop, for example.

Make the repository setup explicit, to express it clearer, although this code will never be run (It does not mean the code is not tested, I removed alias handling code to reproduce the problem, and this code helped fix it)

Signed-off-by: Duy Nguyen <pclouds@gmail.com>
---
 git.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/git.c b/git.c
index bd1d4bb..d84996c 100644
--- a/git.c
+++ b/git.c
@@ -547,6 +547,10 @@ int main(int argc, const char **argv)
 			exit(1);
 		}
 		if (!done_help) {
+			if (!startup_info->have_run_setup_gitdir) {
+				int nongit_ok;
+				setup_git_directory_gently(&nongit_ok);
+			}
 			cmd = argv[0] = help_unknown_cmd(cmd);
 			done_help = 1;
 		} else
-- 
1.7.0.rc1.541.g2da82.dirty
Previous: Nguyễn Thái Ngọc DuyNext: Jonathan Nieder
Message 2 of 4 in “builtins: do not commit pager choice early”
  1. 1/2 builtins: do not commit pager choice earlyNguyễn Thái Ngọc Duy, Mar 25, 2010
  2. 2/2 builtins: setup repository before print unknown command errorNguyễn Thái Ngọc Duy, Mar 25, 2010
  3. Jonathan NiederMar 26, 2010
  4. Jonathan NiederMar 26, 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.