feat: configure fetch refspec after bare clone#13
Conversation
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.
There was a problem hiding this comment.
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 setremote.origin.fetchto+refs/heads/*:refs/remotes/origin/*. - Invoked the helper after bare cloning in
bt repo cloneandbt 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.
| // 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 |
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| // Configure fetch refspec (bare clone does not set this up automatically) | ||
| if err := git.ConfigureRemoteRefspec(barePath); err != nil { |
There was a problem hiding this comment.
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.
| 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) |
| // 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) | ||
| } |
There was a problem hiding this comment.
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.
| // 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) | ||
| } |
There was a problem hiding this comment.
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.
Summary
git clone --bare) do not automatically configure the fetch refspec (remote.origin.fetch), sogit fetchdoes not populate remote tracking branches (refs/remotes/origin/*)ConfigureRemoteRefspec()to automatically set+refs/heads/*:refs/remotes/origin/*after bare clonebt cloneandbt getcommandsTest plan
bt getwith a remote repository and verify.git/configcontainsfetch = +refs/heads/*:refs/remotes/origin/*under[remote "origin"]bt clonewith a remote repository and verify the samegit fetch originin the bare repo after clone and verify remote tracking branches appear underrefs/remotes/origin/bt add <remote-branch>after clone and verify it resolves remote branches correctly