Skip to content

Commit

Permalink
[PATCH] Add "--git-dir" flag to git-rev-parse
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Sep 18, 2005
1 parent 1b0c1e6 commit a8783ee
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a8783ee

Please sign in to comment.