feat: add --default-branch-only flag to pull and sync#179
Merged
Conversation
Add an optional --default-branch-only flag that limits synchronization to
a repository's single default branch instead of mirroring every branch.
Tags are always synced regardless of the flag.
When set, the initial clone uses ReferenceName: HEAD with SingleBranch so
only the default branch is fetched, and the subsequent fetch only mirrors
tags (+refs/tags/*) rather than all heads (+refs/heads/*). The flag is part
of PullOnlyFlags, so it is available on both the `pull` and `sync` commands.
The progress log now reflects the mode ("fetching tags" vs "fetching all
branches and tags"). The flag only applies on the initial clone into the
cache directory; a repository already cached with all branches keeps them.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a --default-branch-only CLI flag to limit synchronization to the repository’s default branch (while always syncing tags), wiring it through pull and sync, and documenting/testing the behavior.
Changes:
- Added
--default-branch-onlyflag to pull/sync flag set and threaded it into pull execution. - Updated clone behavior to support single-branch cloning via go-git options when enabled.
- Added/updated unit tests and README documentation for the new flag.
Show a summary per file
| File | Description |
|---|---|
| src/pull.go | Adds the flag, threads it through pull execution, and alters clone/fetch behavior based on the flag. |
| src/pull_test.go | Adds coverage for clone/fetch options and “tags always synced” across both modes; updates existing tests for new signatures. |
| src/testutils_test.go | Enhances pull-related fakes to record clone/fetch options needed by the new tests. |
| README.md | Documents default-branch-only for both sync and pull usage sections. |
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: 1
…only The fetch step previously used only +refs/tags/* when --default-branch-only was set, so on re-syncs (where the cached repo exists and the clone is skipped) the default branch was never updated and went stale. Instead, refresh the branches already present locally (the single branch the clone checked out) so the cached default branch stays current, while still never pulling down additional remote branches. Tags continue to sync via Tags: git.AllTags. Adds a regression test covering the repo-already-cached re-sync path and updates the README to describe the corrected behaviour. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
boxofyellow
reviewed
Jun 24, 2026
Address review feedback. Previously the re-sync fetch refreshed every branch already present locally, so a repository cached without the flag would still have all of its branches updated, contradicting the "only the single default branch" behaviour. Resolve HEAD to the default branch and build a single refspec for it, so only the default branch is ever refreshed; any other branches already in the cache are left as-is (neither updated nor removed). Add Head() to the GitRepository wrapper to support this. Tests now use a repository with several branches and a non-default HEAD so they prove only the default branch is selected (rather than only one branch existing). Adds a Head-resolution error-path test. README clarifies that the default branch is always refreshed while extra cached branches are left as-is. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
boxofyellow
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an optional
--default-branch-onlyflag to thepullandsynccommands. When set, only the repository's single default branch is synchronized instead of the default behaviour of mirroring all branches. Tags are always synced regardless of the flag.This implements the same capability proposed in #161, adapted to the current
main(which has since added the--source-token/authparameter that #161's base predated), and adds the test coverage and docs that were missing there.How
DefaultBranchOnly boolonPullOnlyFlags, registered as--default-branch-only(defaultfalse). Because it lives onPullOnlyFlags, it is wired into bothpullandsync.Pull->PullManyWithGitImpl->PullWithGitImpl.ReferenceName: plumbing.HEADwithSingleBranch: defaultBranchOnly, so only the default branch is brought in when enabled.+refs/heads/*) by default, or tags only (+refs/tags/*) when limited to the default branch.Tags: git.AllTagskeeps tags syncing in both modes.fetching tags ...vsfetching all branches and tags ....Notes / scope
os.MkdirAll(cacheDir, ...)change, since it alters the existing cache-dir contract and is unrelated to this feature.Tests
SingleBranch,ReferenceName) and fetch refspecs in both modes, that the flag is threaded to every repo, and that tags are always synced in both modes (table test).Verified locally with
go build,go vet,go test ./...(all green) andgofmt.Manual / regression testing
Ran the built binary against
actions/hello-world-docker-action(3 branches + tagsv1,v2):main(no regression on the unflagged path).--default-branch-only-> onlymain, both tags still present.