fix(trail): validate branch name before trail creation · Entire
fix(trail): validate branch name before trail creation
156687b→main·
dipree·4w ago·3 files·+12 added/-0 removed
Reject unsafe/invalid branch names before trail create reaches git
subcommands. In particular, block names starting with '-' so user input
cannot be interpreted as git options during push/ls-remote/delete.
Sessions
8e30ad0076f1View transcript
?\
Fix Trail Creation Branch Handling and ValidationPi·Opus 4.8·1 step
Changes
3
cmd/entire/cli
Mgit_operations.go+3
Mgit_operations_test.go+6
Mtrail_cmd.go+3
351 unmodified lines
352
353
354
355
356
357
358
359
360
351 unmodified lines
// ValidateBranchName checks if a branch name is valid using git check-ref-format.
// Returns an error if the name is invalid or contains unsafe characters.
func ValidateBranchName(ctx context.Context, branchName string) error {
if strings.HasPrefix(branchName, "-") {
return fmt.Errorf("invalid branch name %q", branchName)
}
cmd := exec.CommandContext(ctx, "git", "check-ref-format", "--branch", branchName)
if err := cmd.Run(); err != nil {
return fmt.Errorf("invalid branch name %q", branchName)
Mcmd/entire/cli/git_operations.go+3
36 unmodified lines
37
38
39
40
41
42
43
44
45
46
47
48
36 unmodified lines
return repo
}
func TestValidateBranchNameRejectsLeadingDash(t *testing.T) {
err := ValidateBranchName(context.Background(), "--all")
require.Error(t, err)
require.Contains(t, err.Error(), "invalid branch name")
}
func TestGetCurrentBranch(t *testing.T) {
// Create temp directory for test repo
tmpDir := t.TempDir()
Mcmd/entire/cli/git_operations_test.go+6
611 unmodified lines
612
613
614
615
616
617
618
619
620
611 unmodified lines
if branch == "" {
return errors.New("branch name is required")
}
if err := ValidateBranchName(ctx, branch); err != nil {
return err
}
if statusStr == "" {
statusStr = string(trail.StatusOpen)
}
Mcmd/entire/cli/trail_cmd.go+3