Skip to content

Commit 2f80d1b

Browse files
committed
Merge branch 'rj/branch-copy-and-rename' into maint-2.39
Fix a pair of bugs in 'git branch'. * rj/branch-copy-and-rename: branch: force-copy a branch to itself via @{-1} is a no-op
2 parents 8ca2b1f + cfbd173 commit 2f80d1b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

builtin/branch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,13 +581,13 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
581581
strbuf_release(&logmsg);
582582

583583
strbuf_addf(&oldsection, "branch.%s", interpreted_oldname);
584-
strbuf_release(&oldref);
585584
strbuf_addf(&newsection, "branch.%s", interpreted_newname);
586-
strbuf_release(&newref);
587585
if (!copy && git_config_rename_section(oldsection.buf, newsection.buf) < 0)
588586
die(_("Branch is renamed, but update of config-file failed"));
589-
if (copy && strcmp(oldname, newname) && git_config_copy_section(oldsection.buf, newsection.buf) < 0)
587+
if (copy && strcmp(interpreted_oldname, interpreted_newname) && git_config_copy_section(oldsection.buf, newsection.buf) < 0)
590588
die(_("Branch is copied, but update of config-file failed"));
589+
strbuf_release(&oldref);
590+
strbuf_release(&newref);
591591
strbuf_release(&oldsection);
592592
strbuf_release(&newsection);
593593
}

t/t3204-branch-name-interpretation.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ test_expect_success 'create branch with pseudo-qualified name' '
5757
expect_branch refs/heads/refs/heads/qualified two
5858
'
5959

60+
test_expect_success 'force-copy a branch to itself via @{-1} is no-op' '
61+
git branch -t copiable main &&
62+
git checkout copiable &&
63+
git checkout - &&
64+
git branch -C @{-1} copiable &&
65+
git config --get-all branch.copiable.merge >actual &&
66+
echo refs/heads/main >expect &&
67+
test_cmp expect actual
68+
'
69+
6070
test_expect_success 'delete branch via @{-1}' '
6171
git branch previous-del &&
6272

0 commit comments

Comments
 (0)