summaryrefslogtreecommitdiff
path: root/rev-parse.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@osdl.org>2005-09-18 18:18:30 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-09-18 21:18:34 (GMT)
commita8783eeb7988a20664dade2379d380ee1a199a10 (patch)
tree085f8d34eb6dcf178478a6ab6fdf46bf82d52db2 /rev-parse.c
parent1b0c1e672a417c3f4a46b36497168d6d61dba0cb (diff)
downloadgit-a8783eeb7988a20664dade2379d380ee1a199a10.zip
git-a8783eeb7988a20664dade2379d380ee1a199a10.tar.gz
git-a8783eeb7988a20664dade2379d380ee1a199a10.tar.bz2
[PATCH] Add "--git-dir" flag to git-rev-parse
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'rev-parse.c')
-rw-r--r--rev-parse.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/rev-parse.c b/rev-parse.c
index 6d723f9..0f5630f 100644
--- 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);