Merge pull request #4633 from csware/worktree-delereref Fix deletion of unrelated branch on worktree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 9432df8..760d97f 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -1319,7 +1319,7 @@ static int refdb_fs_backend__delete_tail(
}
/* If a loose reference exists, remove it from the filesystem */
- if (git_buf_joinpath(&loose_path, backend->gitpath, ref_name) < 0)
+ if (git_buf_joinpath(&loose_path, backend->commonpath, ref_name) < 0)
return -1;
diff --git a/tests/worktree/refs.c b/tests/worktree/refs.c
index a10f50a..ea36e80 100644
--- a/tests/worktree/refs.c
+++ b/tests/worktree/refs.c
@@ -134,6 +134,28 @@ void test_worktree_refs__delete_succeeds_after_pruning_worktree(void)
git_reference_free(branch);
}
+void test_worktree_refs__delete_unrelated_branch_on_worktree(void)
+{
+ git_reference *branch;
+
+ cl_git_pass(git_branch_lookup(&branch, fixture.worktree,
+ "merge-conflict", GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_delete(branch));
+
+ git_reference_free(branch);
+}
+
+void test_worktree_refs__delete_unrelated_branch_on_parent(void)
+{
+ git_reference *branch;
+
+ cl_git_pass(git_branch_lookup(&branch, fixture.repo,
+ "merge-conflict", GIT_BRANCH_LOCAL));
+ cl_git_pass(git_branch_delete(branch));
+
+ git_reference_free(branch);
+}
+
void test_worktree_refs__renaming_reference_updates_worktree_heads(void)
{
git_reference *head, *branch, *renamed;