summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-09-10 08:08:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-09-10 08:08:24 (GMT)
commit79553b94f966f3cec6156a68001650ca26a584c4 (patch)
tree37c0d1de2d26a28d67e06993819e8965dd25e942
parent5064d66f5bd86de2f8d5a4b021a616af57f5d8fa (diff)
parent31824d180d4f975e6b130cd9a33a9a0baef3d7ca (diff)
downloadgit-79553b94f966f3cec6156a68001650ca26a584c4.zip
git-79553b94f966f3cec6156a68001650ca26a584c4.tar.gz
git-79553b94f966f3cec6156a68001650ca26a584c4.tar.bz2
Merge branch 'nd/worktree-kill-parse-ref'
"git branch -M a b" while on a branch that is completely unrelated to either branch a or branch b misbehaved when multiple worktree was in use. This has been fixed. * nd/worktree-kill-parse-ref: branch: fix branch renaming not updating HEADs correctly
-rw-r--r--branch.c5
-rwxr-xr-xt/t3200-branch.sh13
-rw-r--r--worktree.c2
3 files changed, 17 insertions, 3 deletions
diff --git a/branch.c b/branch.c
index ce1f8bb..703ded6 100644
--- a/branch.c
+++ b/branch.c
@@ -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 51738fb..d971649 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -162,6 +162,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 'resulting reflog can be shown by log -g' '
oid=$(git rev-parse HEAD) &&
cat >expect <<-EOF &&
diff --git a/worktree.c b/worktree.c
index e28ffbe..c0c5a2b 100644
--- a/worktree.c
+++ b/worktree.c
@@ -30,7 +30,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;