Skip to content

Commit fe25541

Browse files
committed
Switch to worktree on new command
1 parent 747654a commit fe25541

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

cmd/new.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ var newCmd = &cobra.Command{
9898

9999
fmt.Println()
100100
color.Green("✓ Ready to work in %s", worktreePath)
101-
fmt.Println("\nTo switch to this worktree:")
101+
102+
// Ask if user wants to switch to the new worktree
103+
fmt.Println()
104+
if confirmWithDefault("Switch to new worktree?", true) {
105+
return spawnWorktreeShell(worktreePath, branchName)
106+
}
107+
108+
fmt.Println("\nTo switch to this worktree later:")
102109
color.Cyan(" git-wt switch %s", branchName)
103110

104111
return nil

cmd/root.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,21 @@ func confirm(prompt string) bool {
4444
fmt.Scanln(&response)
4545
return response == "y" || response == "Y" || response == "yes" || response == "Yes"
4646
}
47+
48+
// Helper to get user confirmation with configurable default
49+
func confirmWithDefault(prompt string, defaultYes bool) bool {
50+
var response string
51+
if defaultYes {
52+
fmt.Printf("%s [Y/n]: ", prompt)
53+
} else {
54+
fmt.Printf("%s [y/N]: ", prompt)
55+
}
56+
fmt.Scanln(&response)
57+
58+
// Empty response uses default
59+
if response == "" {
60+
return defaultYes
61+
}
62+
63+
return response == "y" || response == "Y" || response == "yes" || response == "Yes"
64+
}

0 commit comments

Comments
 (0)