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

Add "--git-dir" flag to git-rev-parse

From
Linus Torvalds <torvalds@osdl.org>
Date
Sep 18, 2005, 18:18 UTC
Message-ID
<Pine.LNX.4.58.0509181114190.26803@g5.osdl.org>

Especially when you're deep inside the git repository, it's not all that trivial for scripts to figure out where GIT_DIR is if it isn't set.

So add a flag to git-rev-parse to show where it is, since it will have figured it out anyway.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/rev-parse.c b/rev-parse.c
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -191,6 +191,22 @@ int main(int argc, char **argv)
 					puts(prefix);
 				continue;
 			}
+			if (!strcmp(arg, "--git-dir")) {
+				const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
+				static char cwd[PATH_MAX];
+				if (gitdir) {
+					puts(gitdir);
+					continue;
+				}
+				if (!prefix) {
+					puts(".git");
+					continue;
+				}
+				if (!getcwd(cwd, PATH_MAX))
+					die("unable to get current working directory");
+				printf("%s/.git\n", cwd);
+				continue;
+			}
 			if (verify)
 				die("Needed a single revision");
 			show_flag(arg);
Next: David Kågedal
Message 1 of 7 in “Add "--git-dir" flag to git-rev-parse”
  1. Linus TorvaldsSep 18, 2005
  2. Added -d and -e options to the "git" script.David Kågedal, Sep 19, 2005
  3. A Large Angry SCMSep 19, 2005
  4. David KågedalSep 19, 2005
  5. A Large Angry SCMSep 19, 2005
  6. David KågedalSep 19, 2005
  7. Matthias UrlichsSep 19, 2005

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.