Skip to content

Conversation

@philip-gai
Copy link
Member

@philip-gai philip-gai commented Jan 23, 2026

Summary

This PR adds a --batch-size flag to the push and sync commands that allows pushing refs in smaller batches instead of all at once. This helps avoid server-side limits when syncing large repositories with many branches and tags.

Problem

When syncing repositories with a large number of refs (branches + tags), the push operation can fail due to server-side limits on the number of refs that can be pushed in a single operation.

Solution

  • Add --batch-size flag (default: 0, meaning no batching for backward compatibility)
  • When batch size is specified (minimum 10), collect all branch and tag refs and push them in batches
  • Each batch creates explicit refspecs like +refs/heads/main:refs/heads/main instead of wildcards
  • Gracefully handles "already up to date" responses per batch

Changes

  • src/git.go: Add References() method to GitRepository interface
  • src/push.go:
    • Add --batch-size flag with validation (must be 0 or >= 10)
    • Add collectRefs() function to gather branch and tag refs
    • Add pushRefsInBatches() function to push refs in smaller batches
  • src/git_test.go: Add tests for git interface mocks
  • src/push_test.go: Add comprehensive tests for batch validation, ref collection, and batch pushing
  • script/bootstrap: Pin tool dependencies to versions compatible with Go 1.21

Usage

# Default behavior (no batching)
actions-sync push --destination-url https://ghes.example.com --destination-token $TOKEN

# Push refs in batches of 100
actions-sync push --destination-url https://ghes.example.com --destination-token $TOKEN --batch-size 100

Testing

  • All new unit tests pass
  • Docker-based lint and test passes
  • Tested e2e on a GHES instance

Add support for pushing refs in smaller batches to avoid server-side
limits and timeouts when syncing large repositories with many tags/branches.

- Add --batch-size flag (default 0 = no batching, original behavior)
- Add References() method to GitRepository interface
- Implement collectRefs() and pushRefsInBatches() helpers
- Add MinBatchSize validation (must be 0 or >= 10)

This addresses issues where repositories with 1000+ refs fail to sync
to GHES with 'command error on refs/heads/<branch>: failed' errors.
@philip-gai philip-gai requested review from a team as code owners January 23, 2026 17:24
Copilot AI review requested due to automatic review settings January 23, 2026 17:24
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 adds a --batch-size flag to the push and sync commands to enable pushing Git refs in smaller batches, helping avoid server-side limits when syncing repositories with many branches and tags.

Changes:

  • Added --batch-size flag with validation (0 for no batching, or minimum 10)
  • Implemented batching logic to collect and push refs in configurable batch sizes
  • Added comprehensive unit tests for the new functionality
  • Pinned tool dependencies to specific versions for Go 1.21 compatibility

Reviewed changes

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

Show a summary per file
File Description
src/push.go Added batch-size flag, validation, collectRefs() function, and pushRefsInBatches() function to handle batched pushing
src/push_test.go Added comprehensive tests for batch size validation, ref collection, and batched pushing functionality with mock implementations
src/git.go Extended GitRepository interface with References() method and added (unused) RefInfo struct
src/git_test.go Added tests verifying mock implementations satisfy the GitRepository and GitRemote interfaces
script/bootstrap Pinned tool dependencies from @master to specific versions (v0.16.0, v1.6.0) for Go 1.21 compatibility

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

- Remove unused RefInfo struct from git.go
- Remove redundant pushedAny variable tracking in pushRefsInBatches
- Remove incomplete TestPushRefsInBatches_PartialUpToDate test (already covered by existing test case)
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.

1 participant