fix: fall back to git CLI when simple-git fails to detect branch#1074
Open
BeedZiBood wants to merge 1 commit intoVinzent03:masterfrom
Open
fix: fall back to git CLI when simple-git fails to detect branch#1074BeedZiBood wants to merge 1 commit intoVinzent03:masterfrom
BeedZiBood wants to merge 1 commit intoVinzent03:masterfrom
Conversation
simple-git's status parser occasionally returns `current` and `tracking` as null even when the local branch and its upstream are properly configured. When that happens, `branchInfo()` ends up with both fields as `undefined`, the non-null assertions in `pull()` pass `undefined` straight into `git rev-parse`, and the call fails with `fatal: ambiguous argument 'undefined': unknown revision or path not in the working tree.` (issue Vinzent03#1039). Fall back to `git branch --no-color` (already fetched in the same function) for the current branch name, and to the existing `getLocalBranchUpstream` helper (which runs `git rev-parse --abbrev-ref <branch>@{upstream}`) for the tracking branch. Both work reliably regardless of how `git status --porcelain -b -u --null` happens to be parsed.
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.
Summary
Fixes #1039.
SimpleGit.branchInfo()relies onsimple-git'sstatusparser to populatecurrentandtracking. In some setups that parser silently returnsnullfor both even when the branch and its upstream are correctly configured. The values then get propagated asundefinedto the non-null-asserted call sites inpull():undefinedends up serialized into the spawn args and git fails with:This matches every report in #1039 (same stack through
attemptRemoteTask→handleTaskData→ plugintask.error→ throw).Fix
In
branchInfo(), fall back to data sources that don't depend ongit status --porcelain -b -u --nullparsing:branches.currentfrom thegit branch --no-colorcall that's already made in the same function.getLocalBranchUpstream(current)helper, which runsgit rev-parse --abbrev-ref <branch>@{upstream}.Both fallbacks only kick in when
statusreturns null, so the happy path is unchanged.Test plan
pnpm tsc(no errors)pnpm prettier --checkon the touched filepnpm eslinton the touched fileError: undefined / fatal: ambiguous argument 'undefined'; after — pull/sync runs cleanly and reportsPull: Everything is up-to-date/Pulled N files from remote.