fix: avoid shallow-ifying full local clones#74
Merged
Conversation
v0.58.0's `git fetch --no-tags --depth=1 origin $TARGET_BRANCH` runs unconditionally from the pre-push hook. On a full local clone (the typical dev setup), `--depth=1` writes a `.git/shallow` file and truncates `origin/$TARGET_BRANCH` to a single commit, leaving the developer's local main detached from prior history. Users then hit weird states after a `git push` — rebases produce unexpected conflicts because the ancestor commits visible under origin/main have disappeared. Reported by @tmaurin on the same Slack thread as PR #73; the recovery is `git fetch --unshallow`, but we should not put the developer in that state in the first place. Gate `--depth=1` on whether the clone is already shallow: CI (which starts shallow via `actions/checkout` defaults) keeps the fast path; local full clones fetch normally and preserve their history. Add a regression test that runs the hook on a full local clone and asserts both that `.git/shallow` is absent and that `origin/main` retains its full history. Confirmed: the new test fails against v0.58.0 and passes with this fix.
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
Follow-up to #73. v0.58.0's
git fetch --no-tags --depth=1 origin $TARGET_BRANCHruns unconditionally from thepre-pushhook. On a full local clone (the typical dev setup),--depth=1writes a.git/shallowfile and truncatesorigin/$TARGET_BRANCHto a single commit, leaving the developer's localmaindetached from prior history. After agit push, users see weird states — rebases produce unexpected conflicts because the ancestor commits previously visible underorigin/mainhave disappeared.Reported by @tmaurin in the same Slack thread that triggered #73 (recovery:
git fetch --unshallow). @dhalmschlager correctly diagnosed the mechanism and suggested the guard.Reproduction (5 lines of shell on a full clone)
Fix
Gate
--depth=1on whether the clone is already shallow:CI (starts shallow via
actions/checkout@v6defaults) keeps the fast--depth=1path; local full clones fetch normally and preserve their history.Test plan
New regression test in
tests/test_git_branch_linearity.sh: runs the hook on a full local clone and asserts both that.git/shallowis absent and thatorigin/mainretains its full 3-commit history.Confirmed the new test fails against v0.58.0 (
origin/main has 1 commits, expected 3) and passes with this fix.Existing 4 tests from fix: make git-branch-linearity.sh work with shallow CI clones #73 still pass (6/6 total).
Local validation on the real
supply-demand-lngrepo at the commit that originally failed (SHA2778d4937c):.git/shallowafter hookorigin/maincommits after hookGITHUB_HEAD_REFEnd-to-end CI validation in the real repo that was broken. Reopened the failing state of PR #122 (SHA
2778d4937c) with a single change —rev: v0.57.0→ this PR's fix commit — then ran the pre-commit workflow in bothactions/checkoutconfigurations:actions/checkoutfetch-depth: 1Check for git branch linearity... Passed(job)fetch-depth: 0Check for git branch linearity... Passed(job)Validation PRs (now closed): Kpler/supply-demand-lng#124 (shallow) and Kpler/supply-demand-lng#125 (full).