fix(remote): fall back to set-url when remote already exists#127
fix(remote): fall back to set-url when remote already exists#127
Conversation
- Fall back to git remote set-url when git remote add fails - Add RemoteSetURL function for updating existing remote URLs - Add test for RemoteSetURL command arguments Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses failures when configuring a git remote that already exists (e.g., origin) by introducing a git remote set-url path and updating remote handling to avoid remote ... already exists errors (Issue #107).
Changes:
- Add
RemoteSetURLhelper to buildgit remote set-urlcommands. - Update
Plugin.HandleRemoteto attempt updating the remote URL when adding the remote fails. - Add a unit test validating the
RemoteSetURLcommand arguments.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
repo/remote.go |
Adds RemoteSetURL command builder for updating an existing remote’s URL. |
repo/remote_test.go |
Adds a unit test to verify RemoteSetURL constructs the expected command args. |
plugin.go |
Changes remote setup logic to fall back to set-url when remote add fails. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugin.go
Outdated
| if err := execute(repo.RemoteAdd(ctx, p.Config.RemoteName, p.Config.Remote)); err != nil { | ||
| return err | ||
| // If remote already exists, update its URL instead. | ||
| if err := execute(repo.RemoteSetURL(ctx, p.Config.RemoteName, p.Config.Remote)); err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
HandleRemote falls back to RemoteSetURL for any RemoteAdd error, not just the "remote already exists" case described in the PR. This can mask the original failure (e.g., not a git repo, git missing) because the returned error will come from set-url. Consider detecting whether the remote already exists first (e.g., via git config --get remote.<name>.url / a RemoteExists helper) and only calling set-url in that case; otherwise return the original RemoteAdd error.
| // HandleRemote adds the git remote if required. | ||
| // If the remote already exists, it updates the URL instead. | ||
| func (p Plugin) HandleRemote(ctx context.Context) error { |
There was a problem hiding this comment.
There’s no test covering the new fallback behavior in HandleRemote (remote already exists -> update URL). Adding a unit test that sets up a temporary git repo, adds the remote once, and then calls HandleRemote again would verify the fix for #107 and prevent regressions.
- Add RemoteExists helper to check if a named remote already exists - Use RemoteExists in HandleRemote to choose between add and set-url - Add integration test for HandleRemote with pre-existing remote Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Check os.Chdir error return in defer to satisfy errcheck - Use exec.CommandContext instead of exec.Command to satisfy noctx - Add nolint:gosec for test-only git commands with static args Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Break long lines to satisfy golines linter - Remove unused nolint:gosec directives Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
git remote set-urlwhengit remote addfailsRemoteSetURLfunction inrepo/remote.goCloses #107
Test plan
go test ./...)remote_namematches an existing remote (e.g.,origin)🤖 Generated with Claude Code