Skip to content

Fix deepening of shallow clones in latest git#1221

Merged
ecraig12345 merged 1 commit intomainfrom
ecraig/fix-history
Apr 29, 2026
Merged

Fix deepening of shallow clones in latest git#1221
ecraig12345 merged 1 commit intomainfrom
ecraig/fix-history

Conversation

@ecraig12345
Copy link
Copy Markdown
Member

Problem

Something in git 2.54.0 (which seems to be rolling out on GitHub Actions agents as of yesterday) either introduced or surfaced an issue with how beachball handles git fetch operations and attempting to deepen shallow clones:

When a CI shallow clone doesn't have a fetch refspec configured for the target branch (common with actions/checkout single-branch clones), git fetch origin main updates FETCH_HEAD but doesn't move refs/remotes/origin/main. Subsequent git fetch --deepen=N origin main calls have the same problem, so git merge-base origin/main HEAD keeps failing even after deepening, and beachball falls back to a full unshallow unnecessarily.

A secondary workaround existed in ensureSharedHistory to detect this case and run git remote set-branches --add before fetching — but this only ran when the tracking ref was completely absent, leaving the bug open for cases where the ref existed but fetch config was narrow.

Fix

gitFetch now constructs a fully qualified refspec for every fetch, guaranteeing that the local tracking ref is updated regardless of what's in remote.origin.fetch:

git fetch origin +refs/heads/main:refs/remotes/origin/main

In git fetch <remote> +<src>:<dst>:

  • The + means allow divergent branches (in case the remote was force pushed).
  • <src> refs/heads/${branch} is resolved against the remote's advertised refs, not local refs, so it doesn't impact a local ${branch} tracking a different remote. The fully qualified ref is unambiguous. (An earlier version of this change used a bare branch name, which can be silently misresolved, causing git to treat the ref as absent and delete the local tracking ref.)
  • <dst> refs/remotes/${remote}/${branch} is resolved locally and only moves the tracking ref for the remote branch, not the local refs/heads/${branch} or its tracking config.

This also removes the git config --get-all + git remote set-branches --add block from ensureSharedHistory, since it's no longer needed.

Also in this commit

  • gitFetch params remote and branch are now required (they were always passed together; the optional form was dead code).
  • Errors in ensureSharedHistory now consistently use BeachballError.
  • New tests for prior problem scenarios

@ecraig12345 ecraig12345 merged commit e52343a into main Apr 29, 2026
10 checks passed
@ecraig12345 ecraig12345 deleted the ecraig/fix-history branch April 29, 2026 21:27
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.

2 participants