Skip to content

Commit 1745100

Browse files
committed
Remove silent prefix detection from args path in init
When explicit branch names containing slashes were passed to `gh stack init` (e.g. `gh stack init myprefix/branch`), detectPrefix would silently extract the prefix and store it in the stack config. This caused `gh stack add otherbranch` to unexpectedly produce `myprefix/otherbranch` without the user ever opting in. Remove the automatic prefix detection from the args path so that explicit branch names are taken literally. Users who want a prefix should use `--prefix`. The interactive path (no args) continues to prompt for confirmation before setting a prefix.
1 parent dd5ad69 commit 1745100

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

cmd/init.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,6 @@ func runInit(cfg *config.Config, opts *initOptions) error {
149149
return err
150150
}
151151

152-
// Prefix detection (only when --prefix not explicitly set)
153-
if opts.prefix == "" {
154-
if detected := detectPrefix(branches); detected != "" {
155-
opts.prefix = detected
156-
}
157-
}
158-
159152
} else if opts.numbered {
160153
// === NUMBERED PATH (unchanged) ===
161154
if opts.prefix == "" && cfg.IsInteractive() {

cmd/init_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ func TestInit_ImplicitAdopt_Mixed(t *testing.T) {
465465
}
466466

467467
func TestInit_PrefixDetection_ArgsCommonPrefix(t *testing.T) {
468-
// Scenario 9: args all share prefix → set silently
468+
// Explicit branch names with a common prefix should NOT auto-detect
469+
// a prefix — the slash is part of the branch name, not a convention.
470+
// Users who want a prefix should use --prefix.
469471
gitDir := t.TempDir()
470472
restore := git.SetOps(&git.MockOps{
471473
GitDirFn: func() (string, error) { return gitDir, nil },
@@ -481,7 +483,7 @@ func TestInit_PrefixDetection_ArgsCommonPrefix(t *testing.T) {
481483

482484
require.NoError(t, err)
483485
sf, _ := stack.Load(gitDir)
484-
assert.Equal(t, "feat", sf.Stacks[0].Prefix)
486+
assert.Equal(t, "", sf.Stacks[0].Prefix)
485487
}
486488

487489
func TestInit_PrefixDetection_ArgsMixedPrefix(t *testing.T) {
@@ -525,7 +527,8 @@ func TestInit_PrefixDetection_ArgsNoSlash(t *testing.T) {
525527
}
526528

527529
func TestInit_PrefixDetection_NestedPrefix(t *testing.T) {
528-
// Scenario 6: sameen/feat/x → prefix "sameen/feat"
530+
// Explicit branch names with nested slashes should NOT auto-detect
531+
// a prefix — the user typed the full branch name deliberately.
529532
gitDir := t.TempDir()
530533
restore := git.SetOps(&git.MockOps{
531534
GitDirFn: func() (string, error) { return gitDir, nil },
@@ -541,7 +544,7 @@ func TestInit_PrefixDetection_NestedPrefix(t *testing.T) {
541544

542545
require.NoError(t, err)
543546
sf, _ := stack.Load(gitDir)
544-
assert.Equal(t, "sameen/feat", sf.Stacks[0].Prefix)
547+
assert.Equal(t, "", sf.Stacks[0].Prefix)
545548
}
546549

547550
func TestInit_ExplicitPrefixSkipsDetection(t *testing.T) {

0 commit comments

Comments
 (0)