diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-02-24 13:25:53 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-02-24 13:25:53 -0800 |
commit | 8020803f5057601c1c29ffcdbd309905bd26eef7 (patch) | |
tree | d4f0bbfcd50de828c54b8187a98b821c5ad2ce21 | |
parent | Merge branch 'nd/dwim-wildcards-as-pathspecs' (diff) | |
parent | rev-parse: take prefix into account in --git-common-dir (diff) | |
download | tgif-8020803f5057601c1c29ffcdbd309905bd26eef7.tar.xz |
Merge branch 'nd/git-common-dir-fix'
"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
-rw-r--r-- | builtin/rev-parse.c | 3 | ||||
-rwxr-xr-x | t/t2027-worktree-list.sh | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index bd16876df5..cf8487b3b9 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -763,7 +763,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) 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")) { diff --git a/t/t2027-worktree-list.sh b/t/t2027-worktree-list.sh index 75ebb1b4a0..1b1b65a6b0 100755 --- a/t/t2027-worktree-list.sh +++ b/t/t2027-worktree-list.sh @@ -8,6 +8,16 @@ test_expect_success 'setup' ' test_commit init ' +test_expect_success 'rev-parse --git-common-dir on main worktree' ' + git rev-parse --git-common-dir >actual && + echo .git >expected && + test_cmp expected actual && + mkdir sub && + git -C sub rev-parse --git-common-dir >actual2 && + echo sub/.git >expected2 && + test_cmp expected2 actual2 +' + test_expect_success '"list" all worktrees from main' ' echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && test_when_finished "rm -rf here && git worktree prune" && |