Skip to content

[plan] Warn/fail on implausible commit range in shallow checkout before synthesizing rewrite commit #48996

Description

@github-actions

Objective

Add a sanity check that detects an implausible commit range (e.g., tens of thousands of commits for what should be a one- or few-commit branch) in a shallow checkout, and fail fast with a clear warning instead of proceeding to synthesize a potentially huge/incorrect rewrite commit.

Context

In a shallow checkout (default fetch-depth: 1), origin/<base> has no traversable ancestry, so git rev-list --parents --topo-order --reverse <origin/base>..HEAD cannot exclude anything and returns essentially the entire repository history (e.g., 61,008 commits for a repo with ~61k commits on main). This large range then trips merge-commit detection and forces the rewrite path (linearizeRangeAsCommit), which can produce an incorrect result (see companion issue about linearizing against the correct base). Detecting the implausible range early is far cheaper than synthesizing a multi-MB payload only to have it fail a size gate.

Suggested Approach

  1. Locate the code in actions/setup/js/git_helpers.cjs / create_pull_request.cjs that computes the commit range via git rev-list --parents --topo-order --reverse.
  2. After computing the range/count, compare it against a reasonable threshold (e.g., configurable, default maybe 50-100 commits) or compare against the known number of commits the agent's branch should have.
  3. If the range size is implausible for a shallow checkout, emit a clear warning/error log (e.g., "Shallow checkout produced an implausible commit range (N commits); consider increasing fetch-depth") and abort the push attempt (or fall back to requiring a deeper fetch) rather than proceeding to rewrite.
  4. Add a log message referencing the shallow-checkout condition so users can diagnose and apply the fetch-depth workaround.
  5. Add tests simulating a shallow checkout with a large synthetic commit range to verify the new guard triggers.

Files to Modify

  • actions/setup/js/git_helpers.cjs
  • actions/setup/js/create_pull_request.cjs
  • Relevant test files
  • Documentation: mention the fetch-depth workaround in relevant checkout/safe-outputs docs

Acceptance Criteria

  • A shallow checkout with an implausible commit range produces a clear, actionable warning/error before payload synthesis
  • Behavior is configurable or has a sane default threshold
  • Tests cover the new detection logic
  • Docs mention the fetch-depth workaround for large monorepos

Generated by 📋 Plan Command · aut00 · 18.7 AIC · ⌖ 5.78 AIC · ⊞ 6.8K ·
Comment /plan to run again

  • expires on Jul 31, 2026, 2:14 PM UTC-08:00

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions