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

[PATCH] Allow 'git cmd -h' outside of repository

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Aug 28, 2008, 21:28 UTC
Message-ID
<1219958917-22780-1-git-send-email-szeder@ira.uka.de>

Printing usage strings of git commands should obviously not depend on the command being run inside a git repository. However, in case of a command requiring a repository, the command line options are parsed only after it is ensured that the command was started inside a repository, resulting in a 'fatal: Not a git repository' if 'git cmd -h' wasn't executed inside a repository.

To get around this issue, we will check early for the presence of '-h' option, and skip ensuring that the command is run inside a repository.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 git.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/git.c b/git.c
index 37b1d76..af53472 100644
--- a/git.c
+++ b/git.c
@@ -380,6 +380,10 @@ static void handle_internal_command(int argc, const char **argv)
 		struct cmd_struct *p = commands+i;
 		if (strcmp(p->cmd, cmd))
 			continue;
+		/* Don't require repository if only usage string is requested */
+		if (argc > 1 && !strcmp(argv[1], "-h")) {
+			p->option = 0;
+		}
 		exit(run_command(p, argc, argv));
 	}
 }
-- 
1.6.0.1.133.g10dd.dirty
Next: Johannes Schindelin
Message 1 of 4 in “Allow 'git cmd -h' outside of repository”
  1. Allow 'git cmd -h' outside of repositorySZEDER Gábor, Aug 28, 2008
  2. Johannes SchindelinAug 29, 2008
  3. Nguyen Thai Ngoc DuyAug 29, 2008
  4. SZEDER GáborAug 29, 2008

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.