Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ func runInit(cfg *config.Config, opts *initOptions) error {
}
}
} else if len(opts.branches) > 0 {
// Explicit branch names provided — create them
// Explicit branch names provided — apply prefix and create them
prefixed := make([]string, 0, len(opts.branches))
for _, b := range opts.branches {
if opts.prefix != "" {
b = opts.prefix + "/" + b
}
if err := sf.ValidateNoDuplicateBranch(b); err != nil {
cfg.Errorf("branch %q already exists in a stack", b)
return ErrInvalidArgs
Expand All @@ -157,8 +161,9 @@ func runInit(cfg *config.Config, opts *initOptions) error {
return ErrSilent
}
}
Comment thread
skarim marked this conversation as resolved.
Comment thread
skarim marked this conversation as resolved.
prefixed = append(prefixed, b)
}
branches = opts.branches
branches = prefixed
} else {
// Interactive mode
if !cfg.IsInteractive() {
Expand Down
27 changes: 27 additions & 0 deletions cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ func TestInit_PrefixStoredInStack(t *testing.T) {
assert.Equal(t, "feat", sf.Stacks[0].Prefix)
}

func TestInit_PrefixAppliedToExplicitBranches(t *testing.T) {
gitDir := t.TempDir()
var created []string
restore := git.SetOps(&git.MockOps{
GitDirFn: func() (string, error) { return gitDir, nil },
DefaultBranchFn: func() (string, error) { return "main", nil },
CurrentBranchFn: func() (string, error) { return "main", nil },
CreateBranchFn: func(name, base string) error {
created = append(created, name)
return nil
},
})
defer restore()

cfg, outR, errR := config.NewTestConfig()
runInit(cfg, &initOptions{branches: []string{"b1", "b2"}, prefix: "feat"})
output := collectOutput(cfg, outR, errR)

require.NotContains(t, output, "\u2717", "unexpected error")
assert.Equal(t, []string{"feat/b1", "feat/b2"}, created, "branches should be created with prefix")
Comment thread
skarim marked this conversation as resolved.

sf, err := stack.Load(gitDir)
require.NoError(t, err, "loading stack")
names := sf.Stacks[0].BranchNames()
assert.Equal(t, []string{"feat/b1", "feat/b2"}, names, "stack should store prefixed branch names")
}

func TestInit_RerereAlreadyEnabled(t *testing.T) {
gitDir := t.TempDir()
enableRerereCalled := false
Expand Down
Loading