@@ -56,7 +56,7 @@ func runInit(cfg *config.Config, opts *initOptions) error {
5656 if trunk == "" {
5757 trunk , err = git .DefaultBranch ()
5858 if err != nil {
59- cfg .Errorf ("unable to determine default branch: %s \n Use -b to specify the trunk branch" , err )
59+ cfg .Errorf ("unable to determine default branch\n Use -b to specify the trunk branch" )
6060 return nil
6161 }
6262 }
@@ -76,6 +76,14 @@ func runInit(cfg *config.Config, opts *initOptions) error {
7676
7777 currentBranch , _ := git .CurrentBranch ()
7878
79+ // Don't allow initializing a stack if the current branch is already part of another stack
80+ if currentBranch != "" {
81+ if existing := sf .FindStackForBranch (currentBranch ); existing != nil {
82+ cfg .Errorf ("current branch %q is already part of a stack" , currentBranch )
83+ return nil
84+ }
85+ }
86+
7987 var branches []string
8088
8189 if opts .adopt {
@@ -90,7 +98,7 @@ func runInit(cfg *config.Config, opts *initOptions) error {
9098 return nil
9199 }
92100 if err := sf .ValidateNoDuplicateBranch (b ); err != nil {
93- cfg .Errorf ("branch %q already exists in the stack" , b )
101+ cfg .Errorf ("branch %q already exists in a stack" , b )
94102 return nil
95103 }
96104 }
@@ -99,7 +107,7 @@ func runInit(cfg *config.Config, opts *initOptions) error {
99107 // Explicit branch names provided — create them
100108 for _ , b := range opts .branches {
101109 if err := sf .ValidateNoDuplicateBranch (b ); err != nil {
102- cfg .Errorf ("branch %q already exists in the stack" , b )
110+ cfg .Errorf ("branch %q already exists in a stack" , b )
103111 return nil
104112 }
105113 if ! git .BranchExists (b ) {
@@ -144,7 +152,7 @@ func runInit(cfg *config.Config, opts *initOptions) error {
144152 return nil
145153 }
146154 if err := sf .ValidateNoDuplicateBranch (branchName ); err != nil {
147- cfg .Errorf ("branch %q already exists in the stack" , branchName )
155+ cfg .Errorf ("branch %q already exists in a stack" , branchName )
148156 return nil
149157 }
150158 if ! git .BranchExists (branchName ) {
0 commit comments