Bug 2042920

Summary: Checkout of a custom ref fails with a core dump
Product: [Fedora] Fedora Reporter: Petr Šplíchal <psplicha>
Component: gitAssignee: Todd Zullinger <tmz>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: amahdal, besser82, chrisw, johannes, opohorel, pstodulk, sebastian.kisela, tmz
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: git-2.35.0-1.fc36 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-01-25 02:01:20 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Petr Šplíchal 2022-01-20 11:13:02 UTC
Description of problem:
Checking out a manually created ref for the second time
results in a core dump.

Version-Release number of selected component (if applicable):
git-2.35.0-0.1.rc1.fc36.x86_64

Steps to Reproduce:
git clone https://github.com/psss/fmf /tmp/fmf
cd /tmp/fmf
cp .git/refs/remotes/origin/HEAD .git/refs/heads/__DEFAULT__
git checkout -f __DEFAULT__
git checkout -f __DEFAULT__

Actual results:
Switched to branch '__DEFAULT__'
BUG: builtin/checkout.c:1098: should be able to skip past 'refs/heads/' in 'refs/remotes/origin/master'!
Aborted (core dumped)

Expected results:
Checkout works fine second time as well.

Additional info:
Works fine with git-2.34.1-1.fc35.x86_64.

Related fmf issue:
https://github.com/psss/fmf/issues/149

Comment 1 Todd Zullinger 2022-01-20 16:56:09 UTC
Thanks for the report Petr!

This looks to have originated in upstream 9081a421a6 (checkout: fix "branch info" memory leaks, 2021-11-16).

I sent a message upstream (with you on Cc:): https://lore.kernel.org/git/YemTGQZ97vAPUPY0@pobox.com/

Comment 2 Petr Šplíchal 2022-01-21 10:38:39 UTC
Thanks for looking into this so quickly! According to the upstream
discussion I see we're doing unexpected things by copying the
remote ref to refs/heads.

Would you recommend a better way to easily detect the default
origin branch from a script within a repository where arbitrary
branch is currently checked out?

The use case is roughly this:

    git clone ...
    git checkout -b custom-branch
    ...
    git checkout -f <default-branch>
    git reset --hard origin/<default-branch>

Thanks for any hint!

Comment 3 Fedora Update System 2022-01-25 01:59:14 UTC
FEDORA-2022-a63d9a0b84 has been submitted as an update to Fedora 36. https://bodhi.fedoraproject.org/updates/FEDORA-2022-a63d9a0b84

Comment 4 Fedora Update System 2022-01-25 02:01:20 UTC
FEDORA-2022-a63d9a0b84 has been pushed to the Fedora 36 stable repository.
If problem still persists, please make note of it in this bug report.