[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>
Linus Torvalds committed
Sep 18, 2005 at 11:18 UTC
a8783eeb7988a20664dade2379d380ee1a199a10
1 file changed
+16
rev-parse.c
+16
@@ -191,6 +191,22 @@ int main(int argc, char **argv)
191
puts(prefix);
192
continue;
193
}
194
+ if (!strcmp(arg, "--git-dir")) {
195
+ const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
196
+ static char cwd[PATH_MAX];
197
+ if (gitdir) {
198
+ puts(gitdir);
199
+ continue;
200
+ }
201
+ if (!prefix) {
202
+ puts(".git");
203
+ continue;
204
+ }
205
+ if (!getcwd(cwd, PATH_MAX))
206
+ die("unable to get current working directory");
207
+ printf("%s/.git\n", cwd);
208
+ continue;
209
+ }
210
if (verify)
211
die("Needed a single revision");
212
show_flag(arg);