rev-parse: take prefix into account in --git-common-dir
Most of the time, get_git_common_dir() returns an absolute path so prefix is irrelevant. If it returns a relative path (e.g. from the main worktree) then prefixing is required. Noticed-by: Mike Hommey <mh@glandium.org> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
754884255b
commit
17f1365dbc
@ -763,7 +763,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "--git-common-dir")) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "--resolve-git-dir")) {
|
if (!strcmp(arg, "--resolve-git-dir")) {
|
||||||
|
@ -8,6 +8,16 @@ test_expect_success 'setup' '
|
|||||||
test_commit init
|
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' '
|
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 &&
|
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" &&
|
test_when_finished "rm -rf here && git worktree prune" &&
|
||||||
|
Loading…
Reference in New Issue
Block a user