Skip to content

fix: fetch all branch heads so gitStream can diff non-default base branches - #868

Merged
MishaKav merged 1 commit into
mainfrom
CS-7247-fetch-all-branch-heads
Aug 24, 2026
Merged

fix: fetch all branch heads so gitStream can diff non-default base branches#868
MishaKav merged 1 commit into
mainfrom
CS-7247-fetch-all-branch-heads

Conversation

@MishaKav

@MishaKav MishaKav commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

The shallow clone implies --single-branch, so only the default branch is fetched. Any PR whose base is a non-default branch fails git diff <base>...<head> with a bad revision, which surfaces as a misleading PR branch was deleted — run skipped (green check, no automations run).

Reported in CS-7247.
https://linearb.atlassian.net/browse/LINBEE-28439

Changes

  • Detach HEAD, then fetch all branch heads with the same --shallow-since bound, in all 4 templates (Bitbucket + 3 GitLab variants)
  • set -e so a failed fetch aborts the step (the old && chain was fail-fast; a multi-line block is not)

Clone line unchanged, so the 6-month history bound is preserved.

Validation

Reproduced and fixed on linear-b/gitstream-sanity, same PR before and after:

PR base before after
#30668 non-default PR branch was deleted — run skipped, 1 check gitstream success, 5 checks
#30669 default (control) gitstream success gitstream success

Also fixes a second case: a PR whose head is the default branch previously died on refusing to fetch into branch 'refs/heads/main' checked out at ....

Equivalent change already merged to linear-b/cm and verified live.

🤖 Generated with Claude Code

✨ PR Description

Purpose: Enable diffing against non-default base branches by fetching all branch heads in CI pipelines.

Main changes:

  • Updated Bitbucket and GitLab CI YAMLs to fetch all remote branch references
  • Implemented git fetch with +refs/heads/*:refs/heads/* and --shallow-since for efficiency
  • Added explicit git checkout --detach and set -e for improved execution reliability

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Description using Guidelines Learn how

…anches

The shallow clone implies --single-branch, so only the default branch is
fetched. Any PR whose base is a non-default branch fails git diff with a bad
revision, surfacing as a misleading "PR branch was deleted" skip.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@orca-security-us orca-security-us Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed OSS Licenses high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@linearb linearb Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ PR Review

The fix correctly addresses both the non-default base branch diff failure and the "refusing to fetch into checked-out branch" error by detaching HEAD before the broad fetch. The set -e addition is a good hardening measure. One performance concern is worth flagging.

1 issues detected:

🚀 Performance - Fetching all remote branch heads on every pipeline run is O(branches) in both time and bandwidth; for large repos this trades an edge-case bug fix for a guaranteed, systematic slowdown. 🛠️

Details: The refspec +refs/heads/*:refs/heads/* fetches every branch in the remote repository. For large repositories with hundreds or thousands of branches, this will significantly increase pipeline duration and network I/O on every single gitStream run, not just PRs targeting non-default bases. The original code only fetched the one branch it needed.

File: docs/downloads/bitbucket-pipelines.yml (48-48)

🛠️ A suggested code correction is included in the review comments.

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Review using Guidelines Learn how

Comment thread docs/downloads/bitbucket-pipelines.yml

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the downloadable CI templates (GitLab + Bitbucket) to ensure gitStream can successfully diff PRs whose base branch is not the default branch when the repo is cloned shallowly.

Changes:

  • Detach HEAD before fetching to avoid “refusing to fetch into branch ... checked out” failures.
  • Fetch all remote branch heads using the same --shallow-since="6 months ago" bound, so non-default base branches are available for git diff <base>...<head>.
  • Add set -e within the multi-line script blocks to preserve fail-fast behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
docs/downloads/gitlab-shell-ci.yml Detach HEAD and fetch all branch heads with --shallow-since before checking out $head_ref.
docs/downloads/gitlab-k8s-ci.yml Same fetch/detach behavior applied to the Kubernetes-oriented GitLab template.
docs/downloads/gitlab-ci.yml Same fetch/detach behavior applied to the standard GitLab template.
docs/downloads/bitbucket-pipelines.yml Same fetch/detach behavior applied to the Bitbucket Pipelines template.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@MishaKav
MishaKav requested a review from vim-zz August 24, 2026 10:19
@MishaKav
MishaKav enabled auto-merge (squash) August 24, 2026 10:19
@MishaKav
MishaKav merged commit 5e6f374 into main Aug 24, 2026
11 checks passed
@MishaKav
MishaKav deleted the CS-7247-fetch-all-branch-heads branch August 24, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants