fix(git): checkout DWIMs remote-only branches (#277)#278
Merged
Conversation
git-checkout:REF failed with 'not found even after fetch' for branches that exist on a remote but were never checked out locally. git's own DWIM can fail to fire (checkout.guess=false, FETCH_HEAD-only fetch). Resolve it explicitly: when checkout fails as pathspec, find the single remote carrying refs/remotes/<remote>/REF and create the local tracking branch via 'checkout -b REF --track <remote>/REF'. Error on >1 match. Co-Authored-By: Max <noreply>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #277.
git-checkout:REFfailed withnot found even after fetchfor a branch that exists on a remote but was never checked out locally — common when updating a teammate's / bot's MR. git's own DWIM (checkout <branch>→ create local tracking branch) can fail to fire (e.g.checkout.guess=false, or a fetch that only movedFETCH_HEAD).Fix
When the checkout fails as a pathspec error, find the single remote carrying
refs/remotes/<remote>/REFand create the local tracking branch explicitly viagit checkout -b REF --track <remote>/REF. Multiple remotes match → error like git does. No match → existingnot founderror.Tests
TestCheckoutRemoteOnlyBranch(3 cases): resolves a remote-only branch, resolves even withcheckout.guess=false, and still errors on a genuinely missing branch. Full suite: 3197 passed, 87.54% coverage.