Skip to content

Commit dba445f

Browse files
skarimCopilot
andcommitted
Remove dead detectPrefix function and its tests
After removing the silent prefix detection from the args path, detectPrefix has no production callers. Remove the function and its table-driven unit test to avoid maintaining unused code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1745100 commit dba445f

2 files changed

Lines changed: 0 additions & 46 deletions

File tree

cmd/init.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -448,29 +448,6 @@ func promptBranchName(cfg *config.Config, prefix string) (string, error) {
448448
return branchName, nil
449449
}
450450

451-
// detectPrefix finds a common prefix across branches by splitting each
452-
// at its last slash. Returns the prefix (without trailing slash) if all
453-
// branches share the same one, or "" otherwise.
454-
func detectPrefix(branches []string) string {
455-
if len(branches) == 0 {
456-
return ""
457-
}
458-
var common string
459-
for i, b := range branches {
460-
lastSlash := strings.LastIndex(b, "/")
461-
if lastSlash <= 0 {
462-
return "" // no slash or leading slash — no prefix
463-
}
464-
prefix := b[:lastSlash]
465-
if i == 0 {
466-
common = prefix
467-
} else if prefix != common {
468-
return "" // different prefixes
469-
}
470-
}
471-
return common
472-
}
473-
474451
// printWhatsNext prints the scenario-aware "What's next" block after init.
475452
func printWhatsNext(cfg *config.Config, s *stack.Stack, branches []string, hasAdopted bool, prCount int) {
476453
lastBranch := branches[len(branches)-1]

cmd/init_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -798,26 +798,3 @@ func TestInit_TwoPassValidation_InvalidRefName(t *testing.T) {
798798
assert.Contains(t, output, "invalid branch name")
799799
assert.Empty(t, created, "no branches should be created when an arg has an invalid ref name")
800800
}
801-
802-
func TestDetectPrefix(t *testing.T) {
803-
tests := []struct {
804-
name string
805-
branches []string
806-
want string
807-
}{
808-
{"common prefix", []string{"feat/a", "feat/b", "feat/c"}, "feat"},
809-
{"nested prefix", []string{"sameen/feat/a", "sameen/feat/b"}, "sameen/feat"},
810-
{"mixed prefixes", []string{"feat/a", "bug/b"}, ""},
811-
{"no slashes", []string{"auth", "api", "ui"}, ""},
812-
{"empty list", []string{}, ""},
813-
{"single branch with slash", []string{"feat/x"}, "feat"},
814-
{"single branch no slash", []string{"auth"}, ""},
815-
{"leading slash only", []string{"/x"}, ""},
816-
}
817-
for _, tt := range tests {
818-
t.Run(tt.name, func(t *testing.T) {
819-
got := detectPrefix(tt.branches)
820-
assert.Equal(t, tt.want, got)
821-
})
822-
}
823-
}

0 commit comments

Comments
 (0)