diff options
-rw-r--r-- | branch.c | 5 | ||||
-rwxr-xr-x | t/t3200-branch.sh | 13 | ||||
-rw-r--r-- | worktree.c | 2 |
3 files changed, 17 insertions, 3 deletions
@@ -357,8 +357,9 @@ int replace_each_worktree_head_symref(const char *oldref, const char *newref, if (worktrees[i]->is_detached) continue; - if (worktrees[i]->head_ref && - strcmp(oldref, worktrees[i]->head_ref)) + if (!worktrees[i]->head_ref) + continue; + if (strcmp(oldref, worktrees[i]->head_ref)) continue; refs = get_worktree_ref_store(worktrees[i]); diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 9f353c0efc..c5c371888b 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -145,6 +145,19 @@ test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' grep "^0\{40\}.*$msg$" .git/logs/HEAD ' +test_expect_success 'git branch -M should leave orphaned HEAD alone' ' + git init orphan && + ( + cd orphan && + test_commit initial && + git checkout --orphan lonely && + grep lonely .git/HEAD && + test_path_is_missing .git/refs/head/lonely && + git branch -M master mistress && + grep lonely .git/HEAD + ) +' + test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' ' git checkout master && git worktree add -b baz bazdir && diff --git a/worktree.c b/worktree.c index c1ec334b06..7bc36f4343 100644 --- a/worktree.c +++ b/worktree.c @@ -29,7 +29,7 @@ static void add_head_info(struct worktree *wt) target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt), "HEAD", - RESOLVE_REF_READING, + 0, wt->head_sha1, &flags); if (!target) return; |