Skip to content

Commit 1304670

Browse files
committed
flag to specify remote and bypass interactive prompt
1 parent d6e6db7 commit 1304670

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ If a rebase conflict occurs, the operation pauses and prints the conflicted file
179179
| `--upstack` | Only rebase branches from the current branch to the top |
180180
| `--continue` | Continue the rebase after resolving conflicts |
181181
| `--abort` | Abort the rebase and restore all branches to their pre-rebase state |
182+
| `--remote <name>` | Remote to fetch from (defaults to auto-detected remote) |
182183

183184
| Argument | Description |
184185
|----------|-------------|
@@ -208,7 +209,7 @@ gh stack rebase --abort
208209
Fetch, rebase, push, and sync PR state in a single command.
209210

210211
```
211-
gh stack sync
212+
gh stack sync [flags]
212213
```
213214

214215
Performs a safe, non-interactive synchronization of the entire stack:
@@ -219,6 +220,10 @@ Performs a safe, non-interactive synchronization of the entire stack:
219220
4. **Push** — pushes all branches (uses `--force-with-lease` if a rebase occurred)
220221
5. **Sync PRs** — syncs PR state from GitHub and reports the status of each PR
221222

223+
| Flag | Description |
224+
|------|-------------|
225+
| `--remote <name>` | Remote to fetch from and push to (defaults to auto-detected remote) |
226+
222227
**Examples:**
223228

224229
```sh
@@ -242,6 +247,7 @@ When creating new PRs, you will be prompted to enter a title for each one. Press
242247
| `--auto` | Use auto-generated PR titles without prompting |
243248
| `--draft` | Create new PRs as drafts |
244249
| `--skip-prs` | Push branches without creating or updating PRs |
250+
| `--remote <name>` | Remote to push to (defaults to auto-detected remote) |
245251

246252
**Examples:**
247253

cmd/push.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type pushOptions struct {
1616
auto bool
1717
draft bool
1818
skipPRs bool
19+
remote string
1920
}
2021

2122
func PushCmd(cfg *config.Config) *cobra.Command {
@@ -32,6 +33,7 @@ func PushCmd(cfg *config.Config) *cobra.Command {
3233
cmd.Flags().BoolVar(&opts.auto, "auto", false, "Use auto-generated PR titles without prompting")
3334
cmd.Flags().BoolVar(&opts.draft, "draft", false, "Create PRs as drafts")
3435
cmd.Flags().BoolVar(&opts.skipPRs, "skip-prs", false, "Push branches without creating or updating PRs")
36+
cmd.Flags().StringVar(&opts.remote, "remote", "", "Remote to push to (defaults to auto-detected remote)")
3537

3638
return cmd
3739
}
@@ -75,7 +77,7 @@ func runPush(cfg *config.Config, opts *pushOptions) error {
7577
}
7678

7779
// Push all active branches atomically
78-
remote, err := pickRemote(cfg, currentBranch)
80+
remote, err := pickRemote(cfg, currentBranch, opts.remote)
7981
if err != nil {
8082
if !errors.Is(err, errInterrupt) {
8183
cfg.Errorf("%s", err)
@@ -225,11 +227,16 @@ func humanize(s string) string {
225227
}, s)
226228
}
227229

228-
// pickRemote determines which remote to push to. It delegates to
230+
// pickRemote determines which remote to push to. If remoteOverride is
231+
// non-empty, it is returned directly. Otherwise it delegates to
229232
// git.ResolveRemote for config-based resolution and remote listing.
230233
// If multiple remotes exist with no configured default, the user is
231234
// prompted to select one interactively.
232-
func pickRemote(cfg *config.Config, branch string) (string, error) {
235+
func pickRemote(cfg *config.Config, branch, remoteOverride string) (string, error) {
236+
if remoteOverride != "" {
237+
return remoteOverride, nil
238+
}
239+
233240
remote, err := git.ResolveRemote(branch)
234241
if err == nil {
235242
return remote, nil

cmd/rebase.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type rebaseOptions struct {
2020
upstack bool
2121
cont bool
2222
abort bool
23+
remote string
2324
}
2425

2526
type rebaseState struct {
@@ -61,6 +62,7 @@ layer in its commit history, rebasing if necessary.`,
6162
cmd.Flags().BoolVar(&opts.upstack, "upstack", false, "Only rebase branches from current branch to top")
6263
cmd.Flags().BoolVar(&opts.cont, "continue", false, "Continue rebase after resolving conflicts")
6364
cmd.Flags().BoolVar(&opts.abort, "abort", false, "Abort rebase and restore all branches")
65+
cmd.Flags().StringVar(&opts.remote, "remote", "", "Remote to fetch from (defaults to auto-detected remote)")
6466

6567
return cmd
6668
}
@@ -94,7 +96,7 @@ func runRebase(cfg *config.Config, opts *rebaseOptions) error {
9496
}
9597

9698
// Resolve remote for fetch and trunk comparison
97-
remote, err := pickRemote(cfg, currentBranch)
99+
remote, err := pickRemote(cfg, currentBranch, opts.remote)
98100
if err != nil {
99101
if !errors.Is(err, errInterrupt) {
100102
cfg.Errorf("%s", err)

cmd/sync.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111
"github.com/spf13/cobra"
1212
)
1313

14-
type syncOptions struct{}
14+
type syncOptions struct {
15+
remote string
16+
}
1517

1618
func SyncCmd(cfg *config.Config) *cobra.Command {
1719
opts := &syncOptions{}
@@ -37,10 +39,12 @@ conflicts interactively.`,
3739
},
3840
}
3941

42+
cmd.Flags().StringVar(&opts.remote, "remote", "", "Remote to fetch from and push to (defaults to auto-detected remote)")
43+
4044
return cmd
4145
}
4246

43-
func runSync(cfg *config.Config, _ *syncOptions) error {
47+
func runSync(cfg *config.Config, opts *syncOptions) error {
4448
result, err := loadStack(cfg, "")
4549
if err != nil {
4650
return ErrNotInStack
@@ -51,7 +55,7 @@ func runSync(cfg *config.Config, _ *syncOptions) error {
5155
currentBranch := result.CurrentBranch
5256

5357
// Resolve remote once for fetch and push
54-
remote, err := pickRemote(cfg, currentBranch)
58+
remote, err := pickRemote(cfg, currentBranch, opts.remote)
5559
if err != nil {
5660
if !errors.Is(err, errInterrupt) {
5761
cfg.Errorf("%s", err)

0 commit comments

Comments
 (0)