Skip to content

feat: add --default-branch-only flag to pull and sync#179

Merged
philip-gai merged 3 commits into
mainfrom
default-branch-only
Jun 24, 2026
Merged

feat: add --default-branch-only flag to pull and sync#179
philip-gai merged 3 commits into
mainfrom
default-branch-only

Conversation

@philip-gai

Copy link
Copy Markdown
Member

What

Adds an optional --default-branch-only flag to the pull and sync commands. 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 / auth parameter that #161's base predated), and adds the test coverage and docs that were missing there.

How

  • New DefaultBranchOnly bool on PullOnlyFlags, registered as --default-branch-only (default false). Because it lives on PullOnlyFlags, it is wired into both pull and sync.
  • Threaded through Pull -> PullManyWithGitImpl -> PullWithGitImpl.
  • The initial clone uses ReferenceName: plumbing.HEAD with SingleBranch: defaultBranchOnly, so only the default branch is brought in when enabled.
  • The follow-up fetch mirrors all heads (+refs/heads/*) by default, or tags only (+refs/tags/*) when limited to the default branch. Tags: git.AllTags keeps tags syncing in both modes.
  • The progress log now reflects the mode: fetching tags ... vs fetching all branches and tags ....

Notes / scope

  • The flag only takes effect on the initial clone into the cache dir. A repository already cached with all branches keeps them on subsequent runs (documented in the README).
  • Intentionally did not include feat: add --default-branch-only cmdline option #161's incidental os.MkdirAll(cacheDir, ...) change, since it alters the existing cache-dir contract and is unrelated to this feature.

Tests

  • Unit tests assert clone options (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).
  • Existing auth, skip-clone, and error-path tests updated for the new signature.

Verified locally with go build, go vet, go test ./... (all green) and gofmt.

Manual / regression testing

Ran the built binary against actions/hello-world-docker-action (3 branches + tags v1, v2):

  • Default (full) pull -> all 3 branches + both tags. Refs are byte-for-byte identical to main (no regression on the unflagged path).
  • --default-branch-only -> only main, both tags still present.
  • Idempotent re-run -> exit 0, no error on already-up-to-date.
  • Upgrade path (default-branch-only cache -> re-pull without flag) -> correctly expands to all branches.
  • Caveat (full cache -> re-pull with flag) -> keeps existing branches, no error.

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>
Copilot AI review requested due to automatic review settings June 24, 2026 16:14
@philip-gai
philip-gai requested review from a team as code owners June 24, 2026 16:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-only flag 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

Comment thread src/pull.go Outdated
…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>
Comment thread src/pull_test.go
Comment thread src/pull_test.go
Comment thread src/pull_test.go
Comment thread README.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot's findings

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

Comment thread src/pull.go Outdated
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>
@philip-gai
philip-gai merged commit c813a12 into main Jun 24, 2026
4 checks passed
@philip-gai
philip-gai deleted the default-branch-only branch June 24, 2026 17:45
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.

3 participants