mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
b9317d55a3
a9be29c981
(sequencer: make refs generated by the `label` command
worktree-local, 2018-04-25) adds refs/rewritten/ as per-worktree
reference space. Unfortunately (my bad) there are a couple places that
need update to make sure it's really per-worktree.
- add_per_worktree_entries_to_dir() is updated to make sure ref listing
look at per-worktree refs/rewritten/ instead of per-repo one [1]
- common_list[] is updated so that git_path() returns the correct
location. This includes "rev-parse --git-path".
This mess is created by me. I started trying to fix it with the
introduction of refs/worktree, where all refs will be per-worktree
without special treatments. Unfortunate refs/rewritten came before
refs/worktree so this is all we can do.
This also fixes logs/refs/worktree not being per-worktree.
[1] note that ref listing still works sometimes. For example, if you
have .git/worktrees/foo/refs/rewritten/bar AND the directory
.git/worktrees/refs/rewritten, refs/rewritten/bar will show up.
add_per_worktree_entries_to_dir() is only needed when the directory
.git/worktrees/refs/rewritten is missing.
Reported-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
114 lines
3.6 KiB
Bash
Executable file
114 lines
3.6 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='per-worktree refs'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup' '
|
|
test_commit initial &&
|
|
test_commit wt1 &&
|
|
test_commit wt2 &&
|
|
git worktree add wt1 wt1 &&
|
|
git worktree add wt2 wt2 &&
|
|
git checkout initial &&
|
|
git update-ref refs/worktree/foo HEAD &&
|
|
git -C wt1 update-ref refs/worktree/foo HEAD &&
|
|
git -C wt2 update-ref refs/worktree/foo HEAD
|
|
'
|
|
|
|
test_expect_success 'refs/worktree must not be packed' '
|
|
git pack-refs --all &&
|
|
test_path_is_missing .git/refs/tags/wt1 &&
|
|
test_path_is_file .git/refs/worktree/foo &&
|
|
test_path_is_file .git/worktrees/wt1/refs/worktree/foo &&
|
|
test_path_is_file .git/worktrees/wt2/refs/worktree/foo
|
|
'
|
|
|
|
test_expect_success 'refs/worktree are per-worktree' '
|
|
test_cmp_rev worktree/foo initial &&
|
|
( cd wt1 && test_cmp_rev worktree/foo wt1 ) &&
|
|
( cd wt2 && test_cmp_rev worktree/foo wt2 )
|
|
'
|
|
|
|
test_expect_success 'resolve main-worktree/HEAD' '
|
|
test_cmp_rev main-worktree/HEAD initial &&
|
|
( cd wt1 && test_cmp_rev main-worktree/HEAD initial ) &&
|
|
( cd wt2 && test_cmp_rev main-worktree/HEAD initial )
|
|
'
|
|
|
|
test_expect_success 'ambiguous main-worktree/HEAD' '
|
|
mkdir -p .git/refs/heads/main-worktree &&
|
|
test_when_finished rm -f .git/refs/heads/main-worktree/HEAD &&
|
|
cp .git/HEAD .git/refs/heads/main-worktree/HEAD &&
|
|
git rev-parse main-worktree/HEAD 2>warn &&
|
|
grep "main-worktree/HEAD.*ambiguous" warn
|
|
'
|
|
|
|
test_expect_success 'resolve worktrees/xx/HEAD' '
|
|
test_cmp_rev worktrees/wt1/HEAD wt1 &&
|
|
( cd wt1 && test_cmp_rev worktrees/wt1/HEAD wt1 ) &&
|
|
( cd wt2 && test_cmp_rev worktrees/wt1/HEAD wt1 )
|
|
'
|
|
|
|
test_expect_success 'ambiguous worktrees/xx/HEAD' '
|
|
mkdir -p .git/refs/heads/worktrees/wt1 &&
|
|
test_when_finished rm -f .git/refs/heads/worktrees/wt1/HEAD &&
|
|
cp .git/HEAD .git/refs/heads/worktrees/wt1/HEAD &&
|
|
git rev-parse worktrees/wt1/HEAD 2>warn &&
|
|
grep "worktrees/wt1/HEAD.*ambiguous" warn
|
|
'
|
|
|
|
test_expect_success 'reflog of main-worktree/HEAD' '
|
|
git reflog HEAD | sed "s/HEAD/main-worktree\/HEAD/" >expected &&
|
|
git reflog main-worktree/HEAD >actual &&
|
|
test_cmp expected actual &&
|
|
git -C wt1 reflog main-worktree/HEAD >actual.wt1 &&
|
|
test_cmp expected actual.wt1
|
|
'
|
|
|
|
test_expect_success 'reflog of worktrees/xx/HEAD' '
|
|
git -C wt2 reflog HEAD | sed "s/HEAD/worktrees\/wt2\/HEAD/" >expected &&
|
|
git reflog worktrees/wt2/HEAD >actual &&
|
|
test_cmp expected actual &&
|
|
git -C wt1 reflog worktrees/wt2/HEAD >actual.wt1 &&
|
|
test_cmp expected actual.wt1 &&
|
|
git -C wt2 reflog worktrees/wt2/HEAD >actual.wt2 &&
|
|
test_cmp expected actual.wt2
|
|
'
|
|
|
|
test_expect_success 'for-each-ref from main repo' '
|
|
mkdir fer1 &&
|
|
git -C fer1 init repo &&
|
|
test_commit -C fer1/repo initial &&
|
|
git -C fer1/repo worktree add ../second &&
|
|
git -C fer1/repo update-ref refs/bisect/main HEAD &&
|
|
git -C fer1/repo update-ref refs/rewritten/main HEAD &&
|
|
git -C fer1/repo update-ref refs/worktree/main HEAD &&
|
|
git -C fer1/repo for-each-ref --format="%(refname)" | grep main >actual &&
|
|
cat >expected <<-\EOF &&
|
|
refs/bisect/main
|
|
refs/rewritten/main
|
|
refs/worktree/main
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'for-each-ref from linked repo' '
|
|
mkdir fer2 &&
|
|
git -C fer2 init repo &&
|
|
test_commit -C fer2/repo initial &&
|
|
git -C fer2/repo worktree add ../second &&
|
|
git -C fer2/second update-ref refs/bisect/second HEAD &&
|
|
git -C fer2/second update-ref refs/rewritten/second HEAD &&
|
|
git -C fer2/second update-ref refs/worktree/second HEAD &&
|
|
git -C fer2/second for-each-ref --format="%(refname)" | grep second >actual &&
|
|
cat >expected <<-\EOF &&
|
|
refs/bisect/second
|
|
refs/heads/second
|
|
refs/rewritten/second
|
|
refs/worktree/second
|
|
EOF
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_done
|