Skip to content

feat: auto-change directory after setup command#11

Merged
liamawhite merged 1 commit intomainfrom
claude/issue-6-20250812-2015
Aug 12, 2025
Merged

feat: auto-change directory after setup command#11
liamawhite merged 1 commit intomainfrom
claude/issue-6-20250812-2015

Conversation

@liamawhite
Copy link
Owner

Add automatic directory change to newly created repository after successful setup, making the setup command consistent with other worktree commands (add, switch, remove) that also change directories.

Resolves #6

Generated with Claude Code

Add automatic directory change to newly created repository after successful
setup, making the setup command consistent with other worktree commands
(add, switch, remove) that also change directories.

Resolves #6

Co-authored-by: Liam White <liamawhite@users.noreply.github.com>
@claude
Copy link
Contributor

claude bot commented Aug 12, 2025

Claude finished @liamawhite's task —— View job


PR Review: Auto-change directory after setup command

Review Checklist:

  • Read and analyze the changed file (cmd/setup.go)
  • Check consistency with other commands that change directories
  • Review for code quality and best practices
  • Identify potential bugs or issues
  • Assess performance considerations
  • Check for security concerns
  • Evaluate test coverage needs
  • Provide comprehensive feedback

Review Feedback

Code Quality & Best Practices

The implementation follows the established pattern used by other commands (add, switch, remove, clear). The use of fmt.Fprintf(os.Stderr, "WT_CHDIR:%s\n", ...) is consistent with the codebase's directory change mechanism.

Consistency

Excellent consistency with other commands:

  • add: Changes to filepath.Join(wm.GitRoot, branch) (the new worktree)
  • switch: Changes to selectedWorktree (the target worktree)
  • remove: Changes to wm.GitRoot (back to main repo)
  • clear: Changes to wm.GitRoot (back to main repo)
  • setup: Changes to config.RepoName (the newly created repo) ✅

⚠️ Potential Issues

  1. Directory Path Accuracy: The change uses config.RepoName which contains just the repository name (e.g., "worktree" from "liamawhite/worktree"). However, looking at the setup code in pkg/setup/setup.go:84-90, I can see that:

    if err := os.MkdirAll(repoConfig.RepoName, 0755); err != nil {
        return err
    }
    if err := os.Chdir(repoConfig.RepoName); err != nil {
        return err
    }

    The setup process creates and changes into this directory, so using config.RepoName is correct.

  2. Error Handling: The directory change happens after SetupRepository() succeeds, which is appropriate. If setup fails, no directory change is attempted.

Performance Considerations

No performance impact - this is a simple string output to stderr.

Security Considerations

No security concerns:

  • Uses the same RepoName that was already validated during parsing
  • No user input injection risk in the WT_CHDIR output
  • Follows established patterns

⚠️ Test Coverage

Gap identified: While there are integration tests for the setup command (integration/integration_test.go:47), there are no tests that verify:

  1. The WT_CHDIR output is generated
  2. The correct directory path is output
  3. Directory change behavior matches other commands

Recommendation: Consider adding a test case to verify the WT_CHDIR output, similar to:

func TestSetupDirectoryChange(t *testing.T) {
    // Capture stderr and verify WT_CHDIR output contains expected directory
}

📍 Code Location Reference

The change is in cmd/setup.go:45 and follows the exact pattern used in:

  • cmd/add.go:46
  • cmd/switch.go:78
  • cmd/remove.go:89
  • cmd/clear.go:52

Overall Assessment

✅ APPROVED - This is a well-implemented change that:

  • Solves the stated problem (makes setup consistent with other commands)
  • Follows established patterns perfectly
  • Has no significant risks or issues
  • Improves user experience by eliminating manual cd after setup

The only minor improvement would be adding test coverage for the WT_CHDIR behavior, but this is not a blocker for merging.


@liamawhite liamawhite merged commit 69b32aa into main Aug 12, 2025
5 checks passed
@liamawhite liamawhite deleted the claude/issue-6-20250812-2015 branch October 24, 2025 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Auto-change directory after setup command

1 participant