Merge branch 'nd/git-common-dir-fix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 24 Feb 2016 21:25:53 +0000 (13:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Feb 2016 21:25:53 +0000 (13:25 -0800)
"git rev-parse --git-common-dir" used in the worktree feature
misbehaved when run from a subdirectory.

* nd/git-common-dir-fix:
rev-parse: take prefix into account in --git-common-dir

1  2 
builtin/rev-parse.c
diff --combined builtin/rev-parse.c
index bd16876df5ff7bce4fbf348d84a0ebc4ea53e7d7,7a4f2c0b0ccedf958b78b2bdda217bfb269c6b23..cf8487b3b95fcca9a8a96a1562646ee8ddd5b354
@@@ -383,7 -383,7 +383,7 @@@ static int cmd_parseopt(int argc, cons
  
        /* get the usage up to the first line with a -- on it */
        for (;;) {
 -              if (strbuf_getline(&sb, stdin, '\n') == EOF)
 +              if (strbuf_getline(&sb, stdin) == EOF)
                        die("premature end of input");
                ALLOC_GROW(usage, unb + 1, usz);
                if (!strcmp("--", sb.buf)) {
        }
  
        /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
 -      while (strbuf_getline(&sb, stdin, '\n') != EOF) {
 +      while (strbuf_getline(&sb, stdin) != EOF) {
                const char *s;
                const char *help;
                struct option *o;
@@@ -763,7 -763,8 +763,8 @@@ int cmd_rev_parse(int argc, const char 
                                continue;
                        }
                        if (!strcmp(arg, "--git-common-dir")) {
-                               puts(get_git_common_dir());
+                               const char *pfx = prefix ? prefix : "";
+                               puts(prefix_filename(pfx, strlen(pfx), get_git_common_dir()));
                                continue;
                        }
                        if (!strcmp(arg, "--resolve-git-dir")) {