Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed Feb 24, 2016
2 parents e6a6a76 + 17f1365 commit 8020803
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion builtin/rev-parse.c
Expand Up @@ -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")) {
Expand Down
10 changes: 10 additions & 0 deletions t/t2027-worktree-list.sh
Expand Up @@ -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" &&
Expand Down

0 comments on commit 8020803

Please sign in to comment.