File tree Expand file tree Collapse file tree 2 files changed +10
-44
lines changed
Expand file tree Collapse file tree 2 files changed +10
-44
lines changed Original file line number Diff line number Diff line change @@ -28,27 +28,30 @@ func NewCdCommand() *cli.Command {
2828 return & cli.Command {
2929 Name : "cd" ,
3030 Usage : "Output absolute path to worktree" ,
31- Description : "Output the absolute path to the specified worktree.\n \n " +
31+ Description : "Output the absolute path to the specified worktree.\n " +
32+ "If no worktree is specified, outputs the main worktree path (like cd goes to $HOME).\n \n " +
3233 "Usage:\n " +
3334 " Direct: cd \" $(wtp cd feature)\" \n " +
34- " With hook: wtp cd feature\n \n " +
35+ " With hook: wtp cd feature\n " +
36+ " Go home: wtp cd\n \n " +
3537 "To enable the hook for easier navigation:\n " +
3638 " Bash: eval \" $(wtp hook bash)\" \n " +
3739 " Zsh: eval \" $(wtp hook zsh)\" \n " +
3840 " Fish: wtp hook fish | source" ,
39- ArgsUsage : "< worktree-name> " ,
41+ ArgsUsage : "[ worktree-name] " ,
4042 Action : cdToWorktree ,
4143 ShellComplete : completeWorktreesForCd ,
4244 }
4345}
4446
4547func cdToWorktree (_ context.Context , cmd * cli.Command ) error {
4648 args := cmd .Args ()
47- if args .Len () == 0 {
48- return errors .WorktreeNameRequired ()
49- }
5049
51- worktreeName := args .Get (0 )
50+ // Default to main worktree (@) when no argument provided, like cd goes to $HOME
51+ worktreeName := "@"
52+ if args .Len () > 0 {
53+ worktreeName = args .Get (0 )
54+ }
5255
5356 // Get current directory
5457 cwd , err := os .Getwd ()
Original file line number Diff line number Diff line change 11package main
22
33import (
4- "bytes"
54 "context"
65 "os"
76 "path/filepath"
@@ -123,42 +122,6 @@ func TestCdCommand_NoEnvironmentVariableDependency(t *testing.T) {
123122 }
124123}
125124
126- // Test critical error scenarios that users will encounter
127- func TestCdCommand_UserFacingErrors (t * testing.T ) {
128- tests := []struct {
129- name string
130- args []string
131- expectedError string
132- }{
133- {
134- name : "no arguments" ,
135- args : []string {},
136- expectedError : "worktree name is required" ,
137- },
138- }
139-
140- for _ , tt := range tests {
141- t .Run (tt .name , func (t * testing.T ) {
142- app := & cli.Command {
143- Commands : []* cli.Command {
144- NewCdCommand (),
145- },
146- }
147-
148- var buf bytes.Buffer
149- app .Writer = & buf
150-
151- ctx := context .Background ()
152- cmdArgs := []string {"wtp" , "cd" }
153- cmdArgs = append (cmdArgs , tt .args ... )
154-
155- err := app .Run (ctx , cmdArgs )
156- assert .Error (t , err )
157- assert .Contains (t , err .Error (), tt .expectedError )
158- })
159- }
160- }
161-
162125// Test edge cases that could break in production
163126func TestCdCommand_EdgeCases (t * testing.T ) {
164127 tests := []struct {
You can’t perform that action at this time.
0 commit comments