Skip to content

feat: configure fetch refspec after bare clone#13

Merged
amaya382 merged 1 commit into
mainfrom
feat/refspec-setup
Mar 20, 2026
Merged

feat: configure fetch refspec after bare clone#13
amaya382 merged 1 commit into
mainfrom
feat/refspec-setup

Conversation

@amaya382

Copy link
Copy Markdown
Owner

Summary

  • Bare clones (git clone --bare) do not automatically configure the fetch refspec (remote.origin.fetch), so git fetch does not populate remote tracking branches (refs/remotes/origin/*)
  • Added ConfigureRemoteRefspec() to automatically set +refs/heads/*:refs/remotes/origin/* after bare clone
  • Applied to both bt clone and bt get commands

Test plan

  • Run bt get with a remote repository and verify .git/config contains fetch = +refs/heads/*:refs/remotes/origin/* under [remote "origin"]
  • Run bt clone with a remote repository and verify the same
  • Run git fetch origin in the bare repo after clone and verify remote tracking branches appear under refs/remotes/origin/
  • Run bt add <remote-branch> after clone and verify it resolves remote branches correctly

Bare clones do not automatically set up the fetch refspec
(remote.origin.fetch), so remote tracking branches are not populated
when running git fetch. This adds automatic refspec configuration
(+refs/heads/*:refs/remotes/origin/*) after bare clone in both
bt clone and bt get commands.
Copilot AI review requested due to automatic review settings March 20, 2026 04:51
@amaya382 amaya382 self-assigned this Mar 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 post-clone configuration step so bare clones created by bt have a standard fetch refspec that populates remote-tracking branches under refs/remotes/origin/*, improving downstream git fetch / remote-branch resolution behavior.

Changes:

  • Added git.ConfigureRemoteRefspec() helper to set remote.origin.fetch to +refs/heads/*:refs/remotes/origin/*.
  • Invoked the helper after bare cloning in bt repo clone and bt repo get.

Reviewed changes

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

File Description
internal/git/executor.go Introduces ConfigureRemoteRefspec() to write the desired fetch refspec into the bare repo config.
cmd/bt/repo/get.go Calls the new helper after cloning in the bt repo get fresh-clone path.
cmd/bt/repo/clone.go Calls the new helper after cloning in the bt repo clone path.

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

Comment thread internal/git/executor.go
Comment on lines +79 to +86
// ConfigureRemoteRefspec sets up the fetch refspec for a bare repository.
// Bare clones do not automatically configure the refspec, so remote tracking
// branches (refs/remotes/origin/*) are not populated by default.
// This configures the standard refspec: +refs/heads/*:refs/remotes/origin/*
func ConfigureRemoteRefspec(barePath string) error {
executor := NewExecutor(barePath)
_, err := executor.Execute("config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*")
return err

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

Consider adding a focused unit test for ConfigureRemoteRefspec (e.g., initialize a temp bare repo with a remote, run ConfigureRemoteRefspec, then assert git config --get-all remote.origin.fetch equals the expected refspec). This is a small, critical behavior change and is easy to validate without running the full CLI.

Copilot uses AI. Check for mistakes.
Comment thread cmd/bt/repo/get.go
}

// Configure fetch refspec (bare clone does not set this up automatically)
if err := git.ConfigureRemoteRefspec(barePath); err != nil {

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

If ConfigureRemoteRefspec fails, runGet returns without cleaning up destination, even though the clone-failure path removes it. Consider removing the partially-created repository (or at least the bare dir) on this error to keep bt get atomic.

Suggested change
if err := git.ConfigureRemoteRefspec(barePath); err != nil {
if err := git.ConfigureRemoteRefspec(barePath); err != nil {
// Cleanup on failure to keep bt get atomic
os.RemoveAll(destination)

Copilot uses AI. Check for mistakes.
Comment thread cmd/bt/repo/get.go
Comment on lines +100 to +103
// Configure fetch refspec (bare clone does not set this up automatically)
if err := git.ConfigureRemoteRefspec(barePath); err != nil {
return fmt.Errorf("failed to configure remote refspec: %w", err)
}

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

This refspec configuration is only applied on the fresh-clone path. When bt get -u updates an existing repo that was created before this change (or otherwise lacks remote.origin.fetch for refs/remotes/origin/*), updateRepository() will still fetch with the old refspec and won’t populate remote-tracking branches. Consider calling ConfigureRemoteRefspec (or verifying the setting) in the update flow as well.

Copilot uses AI. Check for mistakes.
Comment thread cmd/bt/repo/clone.go
Comment on lines +74 to +77
// Configure fetch refspec (bare clone does not set this up automatically)
if err := git.ConfigureRemoteRefspec(barePath); err != nil {
return fmt.Errorf("failed to configure remote refspec: %w", err)
}

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

No tests in the suite currently assert that bt repo clone itself configures remote.origin.fetch; existing remote e2e tests manually set this config. Updating/adding tests to verify the command writes the refspec (and removing the manual setup) would prevent regressions in this behavior.

Copilot uses AI. Check for mistakes.
@amaya382 amaya382 merged commit 1cbfbfc into main Mar 20, 2026
7 checks passed
@amaya382 amaya382 deleted the feat/refspec-setup branch March 20, 2026 06:44
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