git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Add "--git-dir" flag to git-rev-parse
@ 2005-09-18 18:18 Linus Torvalds
  2005-09-19 10:19 ` [PATCH] Added -d and -e options to the "git" script David Kågedal
  0 siblings, 1 reply; 7+ messages in thread
From: Linus Torvalds @ 2005-09-18 18:18 UTC (permalink / raw)
  To: Junio C Hamano, Git Mailing List


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);

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-09-19 15:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-18 18:18 Add "--git-dir" flag to git-rev-parse Linus Torvalds
2005-09-19 10:19 ` [PATCH] Added -d and -e options to the "git" script David Kågedal
2005-09-19 14:14   ` A Large Angry SCM
2005-09-19 14:24     ` David Kågedal
2005-09-19 14:42       ` A Large Angry SCM
2005-09-19 15:08         ` David Kågedal
2005-09-19 14:42   ` Matthias Urlichs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).