Skip to content

fix: fall back to git CLI when simple-git fails to detect branch#1074

Open
BeedZiBood wants to merge 1 commit intoVinzent03:masterfrom
BeedZiBood:fix/branchinfo-fallback-undetected-branch
Open

fix: fall back to git CLI when simple-git fails to detect branch#1074
BeedZiBood wants to merge 1 commit intoVinzent03:masterfrom
BeedZiBood:fix/branchinfo-fallback-undetected-branch

Conversation

@BeedZiBood
Copy link
Copy Markdown

Summary

Fixes #1039.

SimpleGit.branchInfo() relies on simple-git's status parser to populate current and tracking. In some setups that parser silently returns null for both even when the branch and its upstream are correctly configured. The values then get propagated as undefined to the non-null-asserted call sites in pull():

const localCommit = await this.git.revparse([branchInfo.current!]);
// ...
const upstreamCommit = await this.git.revparse([branchInfo.tracking!]);

undefined ends up serialized into the spawn args and git fails with:

fatal: ambiguous argument 'undefined': unknown revision or path not in the working tree.

This matches every report in #1039 (same stack through attemptRemoteTaskhandleTaskData → plugin task.error → throw).

Fix

In branchInfo(), fall back to data sources that don't depend on git status --porcelain -b -u --null parsing:

  • current — use branches.current from the git branch --no-color call that's already made in the same function.
  • tracking — call the existing getLocalBranchUpstream(current) helper, which runs git rev-parse --abbrev-ref <branch>@{upstream}.

Both fallbacks only kick in when status returns null, so the happy path is unchanged.

Test plan

  • pnpm tsc (no errors)
  • pnpm prettier --check on the touched file
  • pnpm eslint on the touched file
  • Manually verified on an affected vault: before — every commit-and-sync produced Error: undefined / fatal: ambiguous argument 'undefined'; after — pull/sync runs cleanly and reports Pull: Everything is up-to-date / Pulled N files from remote.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: git error on commit

1 participant