Skip to content

fix(CSM-353): avoid full-history fetch when a specific commit + branch is provided - #9

Open
arcappcircle wants to merge 1 commit into
masterfrom
fix/CSM-353
Open

fix(CSM-353): avoid full-history fetch when a specific commit + branch is provided#9
arcappcircle wants to merge 1 commit into
masterfrom
fix/CSM-353

Conversation

@arcappcircle

@arcappcircle arcappcircle commented Aug 2, 2026

Copy link
Copy Markdown

Problem

When git_clone.sh is called with both a commit and a branch, IS_SPECIFIC_COMMIT=true and the script ran git fetch origin "${BRANCH}" with no --depth, i.e. a full-history fetch of the branch. The shallow --depth=1 path 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=1 on the tip may not contain the requested commit.

Change

fetchSpecificCommit() replaces the unconditional full fetch with three stages, cheapest first, each one verifying with git cat-file -e that the commit is actually present before returning:

  1. git fetch --depth=1 origin <commit> - single-commit fetch, supported when the remote enables uploadpack.allowReachableSHA1InWant / uploadpack.allowAnySHA1InWant (GitHub, GitLab, Bitbucket Server and Azure DevOps all do).
  2. Progressive deepen of the branch over AC_GIT_COMMIT_FETCH_DEEPEN_STEPS (default 50 500 5000), stopping as soon as the commit is reachable.
  3. Full-history fetch of the branch (--unshallow when the repo is already shallow, plain fetch otherwise) - 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:

Case Result
GitHub repo, commit ~60 behind tip + branch stage 1 hit, 1 commit fetched (was full history), correct HEAD
Server refusing SHA-in-want, commit 6 behind tip, steps 2 4 50 deepened 2 -> 4 -> 50, correct HEAD
Same, steps 2 3 (never reaches the commit) deepen exhausted -> --unshallow fallback, correct HEAD
Branch-only (no commit) fetch command byte-identical to before, 1 commit

bash -n clean.

Notes for the reviewer

  • Follow-up from the issue discussion (@envergokmen): this needs a component version bump plus a default workflow component version update to reach existing customers. Not part of this PR.
  • LFS and submodule handling is unchanged. LFS fetch still runs against the resolved commit reference.
  • AC_GIT_COMMIT_FETCH_DEEPEN_STEPS is 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

    • Added configurable progressive fetching when retrieving a specific commit.
    • Supports shallow fetches, incremental history deepening, and fallback to the full branch history.
    • Improved checkout behavior for specific commits.
  • Documentation

    • Added guidance for configuring progressive fetch depth.
    • Documented the process for fetching and checking out a specific commit.

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>
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The 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

Layer / File(s) Summary
Fetch strategy implementation
git_clone.sh
COMMIT_FETCH_DEEPEN_STEPS configures fetch depths. fetchSpecificCommit validates commits, deepens the branch, and falls back to full history.
Fetch integration and documentation
git_clone.sh, README.md
The specific-commit path uses fetchSpecificCommit. The README describes the fetch sequence and checkout behavior.

Poem

I’m a rabbit with a commit to find,
Through shallow hops, then hops more kind.
I deepen the branch, step by step,
Or fetch the whole history kept.
Then checkout greets the commit bright—
Safe in the burrow, done just right.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: avoiding full-history fetches when a specific commit and branch are provided.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/CSM-353
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/CSM-353

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 44d318b and 2bd8d93.

📒 Files selected for processing (2)
  • README.md
  • git_clone.sh

Comment thread git_clone.sh
Comment on lines +135 to +142
# 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
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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: Run hasCommit after 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.

Suggested change
# 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.

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.

3 participants