Skip to content

cache selected remote#128

Open
skarim wants to merge 2 commits into
skarim/fix-missing-trunk-branchfrom
skarim/save-selected-remote
Open

cache selected remote#128
skarim wants to merge 2 commits into
skarim/fix-missing-trunk-branchfrom
skarim/save-selected-remote

Conversation

@skarim

@skarim skarim commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Save selected remote to gh-stack.remote git config

Users with multiple git remotes are prompted to choose a remote on every gh stack operation, which is tedious. This adds the ability to persist that choice so it only needs to be made once.

Behavior

When a user interactively selects a remote (because multiple remotes exist and none is configured as a push default), they are now shown a Y/n follow-up prompt offering to save that remote for all future gh stack operations. If accepted, the choice is written to the local git config key gh-stack.remote, and instructions for changing or clearing it are printed:

✓ Saved "upstream" as the default remote for gh stack
To change later, run: git config gh-stack.remote <other-remote>
To clear, run:        git config --unset gh-stack.remote

The saved remote is checked in ResolveRemote after the standard git push config keys (branch.<name>.pushRemote, remote.pushDefault, branch.<name>.remote) but before falling back to listing all remotes. This means per-branch git push configuration still takes precedence, and the --remote flag on individual commands continues to override everything.

All commands that resolve a remote (push, submit, sync, rebase, checkout, link, modify, trunk) go through the shared pickRemote helper, so they all benefit automatically.

Changes

internal/git/gitops.go:

  • Add GetSavedRemote, SaveRemote, ClearRemote methods to Ops interface and defaultOps
  • Check gh-stack.remote in ResolveRemote priority chain (after standard git push config, before remote listing)

internal/git/git.go:

  • Add public wrapper functions for GetSavedRemote, SaveRemote, ClearRemote

internal/git/mock_ops.go:

  • Add mock fields and method implementations for the three new Ops methods

cmd/utils.go:

  • Move pickRemote here from push.go as a shared helper
  • Add confirmSaveRemote helper for the Y/n save prompt
  • After interactive remote selection, prompt to save and print change/clear instructions on confirm

cmd/push.go:

  • Remove pickRemote (moved to utils.go), clean up unused imports

internal/git/gitops_test.go:

  • Add integration tests: ResolveRemote uses saved remote, git push config takes precedence over saved remote, SaveRemote/GetSavedRemote/ClearRemote lifecycle

cmd/push_test.go:

  • Add unit tests: pickRemote saves when confirmed, skips save when declined, skips prompt for single remote, override takes precedence

Users with multiple git remotes are prompted to choose a remote on
every gh stack operation, which is tedious. This adds the ability to
persist that choice so it only needs to be made once.

When a user interactively selects a remote (because multiple remotes
exist and none is configured as a push default), they are now shown a
Y/n follow-up prompt offering to save that remote for all future gh
stack operations. If accepted, the choice is written to the local git
config key `gh-stack.remote`, and instructions for changing or clearing
it are printed.

The saved remote is checked in `ResolveRemote` after the standard git
push config keys (branch.<name>.pushRemote, remote.pushDefault,
branch.<name>.remote) but before falling back to listing all remotes.
This means per-branch git push configuration still takes precedence,
and the --remote flag on individual commands continues to override
everything.

All commands that resolve a remote (push, submit, sync, rebase,
checkout, link, modify, trunk) go through the shared `pickRemote`
helper, so they all benefit automatically.

Changes:

- Add GetSavedRemote, SaveRemote, ClearRemote to the git Ops interface,
  defaultOps implementation, public wrappers, and MockOps
- Check gh-stack.remote in ResolveRemote's priority chain
- Move pickRemote from push.go to utils.go as a shared helper
- Add save-remote confirmation prompt after interactive remote selection
- Add unit tests for pickRemote save/decline/skip/override flows
- Add integration tests for ResolveRemote with saved remote and
  precedence, and for the SaveRemote/GetSavedRemote/ClearRemote
  lifecycle
@skarim skarim marked this pull request as ready for review June 15, 2026 13:44
Copilot AI review requested due to automatic review settings June 15, 2026 13:44

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

This PR adds persistence for the user's remote selection in gh-stack. When a user with multiple git remotes interactively selects a remote, they are now offered a follow-up prompt to save that choice to the gh-stack.remote git config key, so they won't be re-prompted on every operation.

Changes:

  • Added GetSavedRemote, SaveRemote, ClearRemote to the git Ops interface, with corresponding implementations, wrappers, and mock methods
  • Integrated the saved remote check into ResolveRemote's priority chain (after standard git push config, before falling back to remote listing)
  • Moved pickRemote from push.go to utils.go as a shared helper and extended it with a confirm-to-save prompt after interactive selection
Show a summary per file
File Description
internal/git/gitops.go Adds GetSavedRemote/SaveRemote/ClearRemote implementations and integrates saved remote into ResolveRemote
internal/git/git.go Adds public wrapper functions for the three new Ops methods
internal/git/mock_ops.go Adds mock fields and method stubs for the new interface methods
cmd/utils.go Moves pickRemote here from push.go, adds confirmSaveRemote helper with save-on-confirm flow
cmd/push.go Removes old pickRemote and cleans up unused imports
internal/git/gitops_test.go Adds integration tests for saved remote resolution and lifecycle
cmd/push_test.go Adds unit tests for the new pickRemote save/skip/override behaviors

Copilot's findings

Tip

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

  • Files reviewed: 7/7 changed files
  • Comments generated: 2

Comment thread internal/git/git.go Outdated
Comment thread cmd/utils.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of skarim June 15, 2026 14:28 View session
GitHub Advanced Security finished work on behalf of skarim June 15, 2026 14:29
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