Resolve default remote for sync/init when multiple remotes exist#120
Merged
Conversation
bw sync now probes every git remote; any that has the beadwork branch gets fetched, merged, and pushed to. When no remote has it yet, a single remote is picked via: only-one-remote, then git config beadwork.remote, then a remote named origin, then an interactive prompt (TTY only, via term.IsTerminal — no /dev/tty fallback), with the selection persisted to git config so subsequent syncs don't re-prompt. Non-interactive runs fail with a message that names the remotes and the config fix. Drops the .bwconfig remote= fallback shipped with the configurable- default-remote feature; remote selection is now git-config-or-origin. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When `bw init` runs in a repo with 2+ remotes and none have the beadwork branch yet, init now asks the user which remote bw should sync with going forward and persists the choice to git config beadwork.remote. Short-circuits match sync: single-remote and existing git config / origin-by-name skip the prompt silently (no persist needed — sync re-applies the same rules). Unlike sync, init's prompt is not gated on term.IsTerminal. `bw init` is a human-initiated setup step; callers who really can't interact can set git config beadwork.remote beforehand and the resolver is never invoked. Init also now probes every remote for the beadwork branch rather than only the configured one, so fresh clones with a non-origin seed remote bootstrap correctly without needing git config. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
promptForRemoteWithReader and gitConfigSet are used by both the sync and init resolvers; putting them in sync.go was misleading. Move them to their own file and inline the single-use promptForRemote wrapper into the sync resolver. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
makeRemoteResolver now takes a stdin source and is shared by both commands; makeInitRemoteResolver is gone. Init therefore inherits the same isInteractiveStdin gate as sync: non-interactive runs that would otherwise need to prompt now error out with the same "no default remote — ..." message. Callers who can't interact set git config beadwork.remote before running bw init. Tests: TestCmdInitMultiRemotePrompts now stubs isInteractiveStdin to true; the former TestCmdInitMultiRemoteIgnoresTTYStub is inverted to TestCmdInitNonInteractiveFailsWithoutPrompt, mirroring sync's gate test. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
c651d21 to
abab0db
Compare
Replace multi-remote fan-out with single-target sync: targetRemotes now returns the first remote (alphabetically) that has the beadwork branch rather than all of them, emitting a warning to stderr when more than one is found. This removes the three-phase multi-remote loop from syncTo, collapsing it to a straightforward fetch/merge/push against one remote. pushTo is removed; Push inlines the single-call. Tests updated to assert the new behaviour: the primary remote advances and secondary remotes are left untouched.
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.
Previously
bw syncwould push to every remote that had the beadwork branch, andbw initsilently picked one. With multiple remotes this is ambiguous and surprising.This PR introduces a
RemoteResolvercallback throughrepo.Init,repo.ForceReinit,repo.Sync, andrepo.Push. The resolver selects a single remote using a short-circuit chain:originexists, use it silentlygit config beadwork.remoteis set, use thatgit config beadwork.remoteThe prompt logic is shared between
syncandinitviaremote_prompt.go. Each command keeps its ownstdinvariable (syncStdin/initStdin) so tests can drive them independently without shared state.