]> git.ipfire.org Git - thirdparty/git.git/commit
checkout: avoid BUG() when hitting a broken repository
authorJunio C Hamano <gitster@pobox.com>
Sat, 22 Jan 2022 00:58:30 +0000 (16:58 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 22 Jan 2022 01:04:50 +0000 (17:04 -0800)
commit519947b69a9ea1461d5f5afc762823835295b3b2
tree82e241bb271ab51db1f0aad8a98b10893ecd2762
parent9081a421a6dbeeda637df8edb0ebf0da11a05b69
checkout: avoid BUG() when hitting a broken repository

When 9081a421 (checkout: fix "branch info" memory leaks, 2021-11-16)
cleaned up existing memory leaks, we added an unrelated sanity check
to ensure that a local branch is truly local and not a symref to
elsewhere that dies with BUG() otherwise.  This was misguided in two
ways.  First of all, such a tightening did not belong to a leak-fix
patch.  And the condition it detected was *not* a bug in our program
but a problem in user data, where warning() or die() would have been
more appropriate.

As the condition is not fatal (the result of computing the local
branch name in the code that is involved in the faulty check is only
used as a textual label for the commit), let's revert the code to
the original state, i.e. strip "refs/heads/" to compute the local
branch name if possible, and otherwise leave it NULL.  The consumer
of the information in merge_working_tree() is prepared to see NULL
in there and act accordingly.

cf. https://bugzilla.redhat.com/show_bug.cgi?id=2042920

Reported-by: Petr Šplíchal <psplicha@redhat.com>
Reported-by: Todd Zullinger <tmz@pobox.com>
Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
t/t2018-checkout-branch.sh