Skip to content

fix(repo-brancher): use --deepen and --unshallow#5014

Merged
openshift-merge-bot[bot] merged 5 commits intoopenshift:mainfrom
petr-muller:fast-forwarder-speedup-1
Mar 20, 2026
Merged

fix(repo-brancher): use --deepen and --unshallow#5014
openshift-merge-bot[bot] merged 5 commits intoopenshift:mainfrom
petr-muller:fast-forwarder-speedup-1

Conversation

@petr-muller
Copy link
Member

@petr-muller petr-muller commented Mar 15, 2026

Summary

  • Switch retry fetches from git fetch --depth to git fetch --deepen to avoid re-fetching already-downloaded revisions during progressive deepening
  • Fix the deepen-by calculation (Exp2(depth-1) instead of Exp2(depth)) so cumulative depths match the old --depth absolute targets (2, 4, 8, 16, ..., 128)
  • Rename the depth parameter to deepenBy in fetchDeeper to clarify the incremental semantics
  • Add --unshallow fallback (like private-org-sync) when progressive deepening is exhausted, removing the previous hard limit that caused failures on deeply diverged branches
  • Add unit tests for pushBranch, fetchDeeper, and fetchUnshallow

Benchmark (20 repos, 2026-03-19)

Test repos: 5 with no release branch, 5 slightly behind (1-3 commits), 5 far behind (30-200 commits), 5 already synced.

Scenario Vanilla (upstream main) Modified Improvement
Sync (with work) 531s (exit 1) 453s (exit 0) 14.6% faster, 78s saved
No-op (reconciled) 212s (exit 1) 50s (exit 0) 76.5% faster, 163s saved

Vanilla fails on repos 150+ commits behind — --depth 128 max is not enough. The --unshallow fallback in the modified binary handles these cases correctly.

🤖 Generated with Claude Code

Using `--deepen` avoids re-fetching revisions when doing the imcrements.

Assisted-By: Claude Opus 4.6 <noreply@anthropic.com>
…ches

I just discovered there is actually a limit for how deep does the tool
try to go when trying to deepen the fetches to find the connected graph.

Remove the limit by doing a full `--unshallow` fallback.

Assisted-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 15, 2026 03:03
@openshift-ci-robot
Copy link
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Walkthrough

Updated repo-brancher to extend retry depths to 1–9, change progressive fetches to use git fetch --deepen with exponential deepen-by increments, add fetchUnshallow to run git fetch --unshallow on the penultimate iteration, shift terminal failure handling to depth 9, and add unit tests for push/deepen/unshallow behavior.

Changes

Cohort / File(s) Summary
Core logic & fetch helpers
cmd/repo-brancher/main.go
Extend depth loop to 1..9; at depth==8 attempt full-history fetch via new fetchUnshallow; final failure handled at depth==9. Change progressive fetch from --depth <n> to --deepen <deepenBy> and compute deepenBy = 2^(depth-1). Update push retry terminal condition accordingly.
Unit tests
cmd/repo-brancher/main_test.go
Add TestPushBranch, TestFetchDeeper, and TestFetchUnshallow that inject a mock git runner, assert exact git CLI args and error propagation for push, deepen, and unshallow flows.
API surface
cmd/repo-brancher/...
Added fetchUnshallow(logger *logrus.Entry, remote *url.URL, gitCmd gitCmd, repoInfo *config.Info) error. Changed fetchDeeper(..., depth int) errorfetchDeeper(..., deepenBy int) error (semantics changed from absolute depth to deepen-by).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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

Copy link

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

Updates repo-brancher’s retry fetch strategy to progressively deepen a shallow clone using git fetch --deepen, with a final git fetch --unshallow fallback to handle cases where deepening still isn’t sufficient to push the new branch.

Changes:

  • Switch retry fetches from git fetch --depth to git fetch --deepen.
  • Add an --unshallow fallback after progressive deepening is exhausted.
  • Adjust retry loop bounds/message to accommodate the extra unshallow attempt.

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

You can also share your feedback on Copilot code review. Take the survey.

@petr-muller
Copy link
Member Author

/retest-required

@petr-muller
Copy link
Member Author

/hold

reasonable CodeRabbit review, will address

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 17, 2026
petr-muller and others added 2 commits March 19, 2026 18:59
Address review feedback:
- Use Exp2(depth-1) instead of Exp2(depth) so cumulative depths match
  the old --depth absolute targets (2, 4, 8, 16, ..., 128). --deepen
  is incremental, so each call adds to the existing depth.
- Rename `depth` parameter to `deepenBy` in fetchDeeper to clarify
  that --deepen takes an incremental value, not an absolute depth.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test pushBranch, fetchDeeper, and fetchUnshallow using mock gitCmd
to verify correct command construction and error handling:
- pushBranch returns retry=true on "too shallow" errors
- fetchDeeper passes correct --deepen value
- fetchUnshallow passes --unshallow flag

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 19, 2026 18:00
Copy link

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

This PR updates repo-brancher’s retry strategy for pushing new branches from a shallow clone by switching from repeated --depth fetches to progressive --deepen, and falling back to --unshallow to remove the deepening limit and fetch full history when necessary.

Changes:

  • Replace progressive git fetch --depth=N retries with git fetch --deepen N.
  • Add a final fallback to git fetch --unshallow when progressive deepening isn’t sufficient.
  • Add unit tests for pushBranch, fetchDeeper, and fetchUnshallow.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cmd/repo-brancher/main.go Switches retry fetch behavior to --deepen and adds --unshallow fallback.
cmd/repo-brancher/main_test.go Adds tests covering push retry behavior and the new fetch commands.

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

You can also share your feedback on Copilot code review. Take the survey.

@petr-muller
Copy link
Member Author

Addressed all review feedback:

  1. Fixed --deepen calculation: Exp2(depth)Exp2(depth-1) so cumulative depths match the old --depth absolute targets (2, 4, 8, ..., 128). --deepen is incremental, so each call now adds the correct delta.
  2. Renamed parameter: depthdeepenBy in fetchDeeper to clarify the incremental semantics.
  3. Added unit tests: Tests for pushBranch, fetchDeeper, and fetchUnshallow using mock gitCmd.

Also added benchmark results to the PR description.

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 19, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
cmd/repo-brancher/main_test.go (1)

148-153: Consider validating full push arguments for consistency with other tests.

The mock only checks that the first argument is "push" but doesn't verify the remote URL or branch name are passed correctly. This is inconsistent with TestFetchDeeper and TestFetchUnshallow which validate the entire command string, and could miss bugs in argument construction.

♻️ Suggested improvement
 			mockGit := func(_ *logrus.Entry, args ...string) error {
-				if args[0] != "push" {
-					t.Errorf("expected push command, got %v", args)
+				expected := fmt.Sprintf("push %s release-4.18:release-4.18", remote.String())
+				got := strings.Join(args, " ")
+				if got != expected {
+					t.Errorf("expected command %q, got %q", expected, got)
 				}
 				return tc.gitErr
 			}

Note: Adjust the expected format to match the actual arguments pushBranch passes to git.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/repo-brancher/main_test.go` around lines 148 - 153, The mockGit in the
test only asserts args[0]=="push"; update the mock used by Test (the anonymous
mockGit function) to validate the full slice of arguments produced by pushBranch
(e.g., verify the remote URL and branch ref/tip format) instead of just the
first element, mirroring the stricter checks used in
TestFetchDeeper/TestFetchUnshallow; locate the mockGit closure and replace the
simple check with a comparison against the expected []string (constructed the
same way the test uses pushBranch inputs) and call t.Errorf with the full args
on mismatch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/repo-brancher/main_test.go`:
- Around line 148-153: The mockGit in the test only asserts args[0]=="push";
update the mock used by Test (the anonymous mockGit function) to validate the
full slice of arguments produced by pushBranch (e.g., verify the remote URL and
branch ref/tip format) instead of just the first element, mirroring the stricter
checks used in TestFetchDeeper/TestFetchUnshallow; locate the mockGit closure
and replace the simple check with a comparison against the expected []string
(constructed the same way the test uses pushBranch inputs) and call t.Errorf
with the full args on mismatch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bbad4b6e-ffae-4a95-a978-8a4861db316c

📥 Commits

Reviewing files that changed from the base of the PR and between 5b22732 and a45352e.

📒 Files selected for processing (1)
  • cmd/repo-brancher/main_test.go

@openshift-ci-robot
Copy link
Contributor

Pipeline controller notification

No second-stage tests were triggered for this PR.

This can happen when:

  • The changed files don't match any pipeline_run_if_changed patterns
  • All files match pipeline_skip_if_only_changed patterns
  • No pipeline-controlled jobs are defined for the main branch

Use /test ? to see all available tests.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 20, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 20, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: petr-muller, Prucek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 20, 2026
@petr-muller
Copy link
Member Author

/test images

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 20, 2026

@petr-muller: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/breaking-changes a45352e link false /test breaking-changes

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot bot merged commit c0b6d98 into openshift:main Mar 20, 2026
12 of 13 checks passed
@petr-muller petr-muller deleted the fast-forwarder-speedup-1 branch March 20, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants