Skip to content

Commit b9317d5

Browse files
pcloudsgitster
authored andcommitted
Make sure refs/rewritten/ is per-worktree
a9be29c (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 <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90d31ff commit b9317d5

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

path.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ static struct common_dir common_list[] = {
115115
{ 1, 1, 0, "logs" },
116116
{ 1, 1, 1, "logs/HEAD" },
117117
{ 0, 1, 1, "logs/refs/bisect" },
118+
{ 0, 1, 1, "logs/refs/rewritten" },
119+
{ 0, 1, 1, "logs/refs/worktree" },
118120
{ 0, 1, 0, "lost-found" },
119121
{ 0, 1, 0, "objects" },
120122
{ 0, 1, 0, "refs" },
121123
{ 0, 1, 1, "refs/bisect" },
124+
{ 0, 1, 1, "refs/rewritten" },
122125
{ 0, 1, 1, "refs/worktree" },
123126
{ 0, 1, 0, "remotes" },
124127
{ 0, 1, 0, "worktrees" },

refs/files-backend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ static void files_ref_path(struct files_ref_store *refs,
214214
}
215215

216216
/*
217-
* Manually add refs/bisect and refs/worktree, which, being
217+
* Manually add refs/bisect, refs/rewritten and refs/worktree, which, being
218218
* per-worktree, might not appear in the directory listing for
219219
* refs/ in the main repo.
220220
*/
221221
static void add_per_worktree_entries_to_dir(struct ref_dir *dir, const char *dirname)
222222
{
223-
const char *prefixes[] = { "refs/bisect/", "refs/worktree/" };
223+
const char *prefixes[] = { "refs/bisect/", "refs/worktree/", "refs/rewritten/" };
224224
int ip;
225225

226226
if (strcmp(dirname, "refs/"))

t/t1415-worktree-refs.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,39 @@ test_expect_success 'reflog of worktrees/xx/HEAD' '
7676
test_cmp expected actual.wt2
7777
'
7878

79+
test_expect_success 'for-each-ref from main repo' '
80+
mkdir fer1 &&
81+
git -C fer1 init repo &&
82+
test_commit -C fer1/repo initial &&
83+
git -C fer1/repo worktree add ../second &&
84+
git -C fer1/repo update-ref refs/bisect/main HEAD &&
85+
git -C fer1/repo update-ref refs/rewritten/main HEAD &&
86+
git -C fer1/repo update-ref refs/worktree/main HEAD &&
87+
git -C fer1/repo for-each-ref --format="%(refname)" | grep main >actual &&
88+
cat >expected <<-\EOF &&
89+
refs/bisect/main
90+
refs/rewritten/main
91+
refs/worktree/main
92+
EOF
93+
test_cmp expected actual
94+
'
95+
96+
test_expect_success 'for-each-ref from linked repo' '
97+
mkdir fer2 &&
98+
git -C fer2 init repo &&
99+
test_commit -C fer2/repo initial &&
100+
git -C fer2/repo worktree add ../second &&
101+
git -C fer2/second update-ref refs/bisect/second HEAD &&
102+
git -C fer2/second update-ref refs/rewritten/second HEAD &&
103+
git -C fer2/second update-ref refs/worktree/second HEAD &&
104+
git -C fer2/second for-each-ref --format="%(refname)" | grep second >actual &&
105+
cat >expected <<-\EOF &&
106+
refs/bisect/second
107+
refs/heads/second
108+
refs/rewritten/second
109+
refs/worktree/second
110+
EOF
111+
test_cmp expected actual
112+
'
113+
79114
test_done

0 commit comments

Comments
 (0)