fix: fetch all branch heads so gitStream can diff non-default base branches - #868
Conversation
…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>
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| OSS Licenses | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
There was a problem hiding this comment.
✨ 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
There was a problem hiding this comment.
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
HEADbefore 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 forgit diff <base>...<head>. - Add
set -ewithin 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.
The shallow clone implies
--single-branch, so only the default branch is fetched. Any PR whose base is a non-default branch failsgit diff <base>...<head>with a bad revision, which surfaces as a misleadingPR branch was deleted — run skipped(green check, no automations run).Reported in CS-7247.
https://linearb.atlassian.net/browse/LINBEE-28439
Changes
--shallow-sincebound, in all 4 templates (Bitbucket + 3 GitLab variants)set -eso 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 branch was deleted — run skipped, 1 checkgitstream success, 5 checksgitstream successgitstream successAlso 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/cmand 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:
git fetchwith+refs/heads/*:refs/heads/*and--shallow-sincefor efficiencygit checkout --detachandset -efor improved execution reliabilityGenerated 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