Merge branch 'ab/checkout-branch-info-leakfix'

We added an unrelated sanity checking that leads to a BUG() while
plugging a leak, which triggered in a repository with symrefs in
the local branch namespace that point at a ref outside.  Partially
revert the change to avoid triggering the BUG().

* ab/checkout-branch-info-leakfix:
  checkout: avoid BUG() when hitting a broken repository
This commit is contained in:
Junio C Hamano 2022-01-24 09:14:46 -08:00
Родитель 7ea759cf9b 519947b69a
Коммит c6e19e47a6
2 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -1094,9 +1094,6 @@ static int switch_branches(const struct checkout_opts *opts,
const char *p; const char *p;
if (skip_prefix(old_branch_info.path, prefix, &p)) if (skip_prefix(old_branch_info.path, prefix, &p))
old_branch_info.name = xstrdup(p); old_branch_info.name = xstrdup(p);
else
BUG("should be able to skip past '%s' in '%s'!",
prefix, old_branch_info.path);
} }
if (opts->new_orphan_branch && opts->orphan_from_empty_tree) { if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {

Просмотреть файл

@ -85,6 +85,19 @@ test_expect_success 'setup' '
git branch -m branch1 git branch -m branch1
' '
test_expect_success 'checkout a branch without refs/heads/* prefix' '
git clone --no-tags . repo-odd-prefix &&
(
cd repo-odd-prefix &&
origin=$(git symbolic-ref refs/remotes/origin/HEAD) &&
git symbolic-ref refs/heads/a-branch "$origin" &&
git checkout -f a-branch &&
git checkout -f a-branch
)
'
test_expect_success 'checkout -b to a new branch, set to HEAD' ' test_expect_success 'checkout -b to a new branch, set to HEAD' '
test_when_finished " test_when_finished "
git checkout branch1 && git checkout branch1 &&