Skip to content

fix: pass --depth to git fetch step to match checkout fetch-depth#35730

Merged
dsyme merged 1 commit into
mainfrom
fix/fetch-step-respects-depth
May 29, 2026
Merged

fix: pass --depth to git fetch step to match checkout fetch-depth#35730
dsyme merged 1 commit into
mainfrom
fix/fetch-step-respects-depth

Conversation

@dsyme
Copy link
Copy Markdown
Collaborator

@dsyme dsyme commented May 29, 2026

fix: pass --depth to git fetch step to match checkout fetch-depth

Summary

Fixes a gap where the git fetch command emitted by the workflow compiler ignored the fetch-depth setting configured on the checkout step. Both generateFetchStepLines and buildSafeOutputsFetchRefsStep now derive a --depth=N flag from the resolved checkout configuration and inject it into the generated fetch command, matching the depth behaviour of the surrounding checkout step.

Changes

pkg/workflow/checkout_step_generator.go — core fix

  • generateFetchStepLines reads resolvedCheckout.fetchDepth to compute the depth flag.
  • Defaults to --depth=1 when fetchDepth is unset (nil).
  • Omits --depth entirely when fetchDepth is 0 (full history).
  • Injects the computed flag into the generated git fetch invocation.

pkg/workflow/compiler_safe_outputs_steps.go — parity fix

  • buildSafeOutputsFetchRefsStep gains a fetchDepth *int parameter.
  • Applies the same --depth derivation logic as generateFetchStepLines.
  • All call sites updated to pass matchedEntry.fetchDepth.

pkg/workflow/checkout_manager_test.go — new test coverage

  • Four new cases for generateFetchStepLines:
    • Default (nil fetch-depth) → --depth=1
    • Explicit depth=1 → --depth=1
    • Depth=0 (full history) → no --depth flag
    • Depth=N (arbitrary) → --depth=N

pkg/workflow/compiler_safe_outputs_steps_test.go — updated assertions

  • Existing TestBuildSharedPRCheckoutSteps cases updated to assert --depth=1 appears in the generated fetch step.

Risk

Low. No behavioural change for workflows that did not set fetch-depth; those continue to get --depth=1, which was already the effective default for the surrounding checkout step. Workflows explicitly setting fetch-depth: 0 (full clone) will now correctly propagate that intent to the fetch step.

Generated by PR Description Updater for issue #35730 · sonnet46 1M ·

The generateFetchStepLines and buildSafeOutputsFetchRefsStep functions
emitted a bare 'git fetch origin <refspecs>' with no depth constraint.
When the original actions/checkout used the default fetch-depth: 1
(shallow clone), the subsequent git fetch ignored that constraint and
fetched full unbounded history — catastrophic for large monorepos.

Fix: mirror the fetchDepth from the resolvedCheckout entry onto the
git fetch command:
  - nil (default, shallow) → --depth=1
  - *fetchDepth > 0        → --depth=N
  - *fetchDepth == 0       → no flag (full history explicitly requested)

Adds test cases for all three cases in TestGenerateFetchStep and
updates the safe_outputs fetch step assertions to expect --depth=1.
Copilot AI review requested due to automatic review settings May 29, 2026 15:35
@github-actions
Copy link
Copy Markdown
Contributor

✅ smoke-ci: safeoutputs CLI comment + comment-memory run (26646532528)

Generated by 🧪 Smoke CI for issue #35730 ·

@github-actions
Copy link
Copy Markdown
Contributor

Comment Memory

CI lights the path
Green checks bloom at dawn
Quiet bots still sing

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

Generated by 🧪 Smoke CI for issue #35730 ·

@dsyme dsyme merged commit a9e799b into main May 29, 2026
38 of 39 checks passed
@dsyme dsyme deleted the fix/fetch-step-respects-depth branch May 29, 2026 15:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a bug where additional git fetch steps generated after actions/checkout lacked a depth flag, causing full-history fetches even when the checkout was shallow. The fix mirrors the resolved checkout's fetchDepth onto the fetch command in both the agent and safe_outputs paths.

Changes:

  • generateFetchStepLines now appends --depth=N based on entry.fetchDepth (nil → 1, 0 → omit, N → N).
  • buildSafeOutputsFetchRefsStep gains a fetchDepth *int parameter and applies the same logic.
  • New unit tests cover nil/1/0/N depth cases; safe_outputs tests assert --depth=1.
Show a summary per file
File Description
pkg/workflow/checkout_step_generator.go Adds depth flag derivation to agent-job fetch step
pkg/workflow/compiler_safe_outputs_steps.go Threads fetchDepth into safe_outputs fetch step and applies depth flag
pkg/workflow/checkout_manager_test.go New depth-handling cases for generateFetchStepLines
pkg/workflow/compiler_safe_outputs_steps_test.go Asserts --depth=1 appears in cross-repo safe_outputs fetch steps

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 0

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.

2 participants