fix(CSM-353): avoid full-history fetch when a specific commit + branch is provided - #9
fix(CSM-353): avoid full-history fetch when a specific commit + branch is provided#9arcappcircle wants to merge 1 commit into
Conversation
When a commit and a branch were both provided, the branch was fetched without --depth, pulling its whole history. Try a shallow fetch of the commit itself first, then deepen the branch progressively, and only fall back to the full fetch when the commit is still not reachable. Co-authored-by: burako <burako@appcircle.io>
📝 WalkthroughWalkthroughChangesThe clone script adds progressive fetching for specific commits. It tries direct and progressively deeper fetches before using full branch history. The README documents the configuration and fetch behavior. Specific-Commit Fetching
Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@git_clone.sh`:
- Around line 135-142: The full-history fallback in git_clone.sh, within
fetchSpecificCommit, must validate the requested commit after fetching: call
hasCommit and return nonzero if ${COMMIT} remains unavailable. In README.md at
line 29, retain the “always checked out” statement only once this final
validation is enforced.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e7b5db4a-1206-4b3e-bc4c-9a8fbd3de600
📒 Files selected for processing (2)
README.mdgit_clone.sh
| # 3) Last resort: the full history fetch of the branch, the previous behavior. | ||
| echo "${COMMIT} is not within the deepened history, fetching the full history of ${BRANCH}." | ||
| if [ -f .git/shallow ]; then | ||
| runCommand git fetch --unshallow origin "${BRANCH}" | ||
| else | ||
| runCommand git fetch origin "${BRANCH}" | ||
| fi | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Verify the commit after the full-history fetch.
A full fetch of ${BRANCH} can succeed when ${COMMIT} is not reachable from that branch. fetchSpecificCommit then returns success without the requested commit. The later checkout can fail.
git_clone.sh#L135-L142: RunhasCommitafter the full-history fetch. Return nonzero if the commit is still unavailable.README.md#L29-L29: Keep the “always checked out” statement only after the final validation exists.
Proposed fix
if [ -f .git/shallow ]; then
runCommand git fetch --unshallow origin "${BRANCH}"
else
runCommand git fetch origin "${BRANCH}"
fi
+ hasCommit📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # 3) Last resort: the full history fetch of the branch, the previous behavior. | |
| echo "${COMMIT} is not within the deepened history, fetching the full history of ${BRANCH}." | |
| if [ -f .git/shallow ]; then | |
| runCommand git fetch --unshallow origin "${BRANCH}" | |
| else | |
| runCommand git fetch origin "${BRANCH}" | |
| fi | |
| } | |
| # 3) Last resort: the full history fetch of the branch, the previous behavior. | |
| echo "${COMMIT} is not within the deepened history, fetching the full history of ${BRANCH}." | |
| if [ -f .git/shallow ]; then | |
| runCommand git fetch --unshallow origin "${BRANCH}" | |
| else | |
| runCommand git fetch origin "${BRANCH}" | |
| fi | |
| hasCommit | |
| } |
📍 Affects 2 files
git_clone.sh#L135-L142(this comment)README.md#L29-L29
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@git_clone.sh` around lines 135 - 142, The full-history fallback in
git_clone.sh, within fetchSpecificCommit, must validate the requested commit
after fetching: call hasCommit and return nonzero if ${COMMIT} remains
unavailable. In README.md at line 29, retain the “always checked out” statement
only once this final validation is enforced.
Problem
When
git_clone.shis called with both a commit and a branch,IS_SPECIFIC_COMMIT=trueand the script rangit fetch origin "${BRANCH}"with no--depth, i.e. a full-history fetch of the branch. The shallow--depth=1path only existed in the no-commit branch. On large repositories (surfaced with DünyaKatılım) this makes the clone step very slow.The full fetch was intentional: an arbitrary commit SHA may not be the branch tip, so
--depth=1on the tip may not contain the requested commit.Change
fetchSpecificCommit()replaces the unconditional full fetch with three stages, cheapest first, each one verifying withgit cat-file -ethat the commit is actually present before returning:git fetch --depth=1 origin <commit>- single-commit fetch, supported when the remote enablesuploadpack.allowReachableSHA1InWant/uploadpack.allowAnySHA1InWant(GitHub, GitLab, Bitbucket Server and Azure DevOps all do).AC_GIT_COMMIT_FETCH_DEEPEN_STEPS(default50 500 5000), stopping as soon as the commit is reachable.--unshallowwhen the repo is already shallow, plainfetchotherwise) - the previous behavior, now only as a last resort.The checkout guarantee is unchanged: the script does not proceed until the requested commit object exists locally.
Untouched paths: branch-only, tag-only, and commit-without-branch behave exactly as before.
Verification
Ran the script directly for each stage:
2 4 502 3(never reaches the commit)--unshallowfallback, correct HEADbash -nclean.Notes for the reviewer
AC_GIT_COMMIT_FETCH_DEEPEN_STEPSis documented in the README as an advanced escape hatch and is not exposed as a component input to keep the step UI unchanged.Linear: CSM-353
Created on behalf of burako@appcircle.io via Arc.
Summary by CodeRabbit
New Features
Documentation