-
Notifications
You must be signed in to change notification settings - Fork 10
Refine list column width calculations #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughRefactors width and spacing calculations in the list rendering logic by introducing Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces repository-specific worktree isolation by changing the default base directory from ../worktrees to ../worktrees/${WTP_REPO_BASENAME}, where ${WTP_REPO_BASENAME} expands to the repository's directory name. This prevents conflicts when multiple repositories use the same parent directory.
Key changes:
- Added
expandBaseDirVariables()function to expand${WTP_REPO_BASENAME}placeholder in base directory paths - Updated default
base_dirconstant to include the placeholder - Added legacy worktree layout detection and migration warnings for existing worktrees
- Refactored test utilities to improve test reliability across different environments (replaced permission-based test failures with file/symlink-based approaches)
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/config/config.go | Added placeholder expansion logic and updated default base directory constant |
| internal/config/config_test.go | Added tests for variable expansion and updated existing tests to use new default |
| cmd/wtp/list.go | Added legacy layout warnings and minor refactoring to extract root command |
| cmd/wtp/remove.go | Added legacy layout warnings, refactored into smaller functions, and simplified base directory resolution |
| cmd/wtp/cd.go | Added legacy layout warnings and simplified base directory resolution |
| cmd/wtp/legacy_warning.go | New file implementing legacy worktree layout detection and migration suggestions |
| cmd/wtp/legacy_warning_test.go | Tests for legacy layout detection logic |
| cmd/wtp/worktree_managed.go | Optimized path conversion to avoid redundant absolute path conversions |
| cmd/wtp/worktree_managed_test.go | Tests for worktree management logic with new default layout |
| cmd/wtp/init.go | Updated default config template and added test hook for file writing |
| test/e2e/worktree_test.go | Updated e2e test to verify new worktree path structure |
| test/e2e/hook_streaming_test.go | Updated test path expectations for new layout |
| internal/hooks/executor_test.go | Improved test reliability by using files/symlinks instead of permissions |
| cmd/wtp/remove_test.go | Updated mock paths to reflect new layout and added ErrWriter discard |
| cmd/wtp/list_test.go | Updated mock paths and added ErrWriter discard to suppress warnings in tests |
| cmd/wtp/cd_test.go | Updated mock paths to reflect new layout |
| cmd/wtp/init_test.go | Updated test expectations and added write file mock |
| docs/architecture.md | Updated documentation to reflect new default path structure |
| README.md | Updated examples and added breaking change notice |
Comments suppressed due to low confidence (1)
cmd/wtp/legacy_warning.go:1
- Same issue as in config.go -
filepath.Base()is called onrepoRootwithout cleaning the path first. SincerepoRootis cleaned on line 75, this is safe indetectLegacyWorktreeMigrations(), but the same pattern should be applied consistently or the function should document that it expects a clean path.
package main
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/config/config.go
Outdated
| return baseDir | ||
| } | ||
|
|
||
| repoBaseName := filepath.Base(repoRoot) |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function doesn't handle trailing slashes in repoRoot properly. filepath.Base(\"/home/user/project/\") returns \"project\" on Unix but the behavior can be inconsistent. While there's a test case for this scenario (line 54-58 in config_test.go), the actual expansion function should clean the path first to ensure consistent behavior. Consider adding repoRoot = filepath.Clean(repoRoot) before calling filepath.Base().
| repoBaseName := filepath.Base(repoRoot) | |
| cleanRepoRoot := filepath.Clean(repoRoot) | |
| repoBaseName := filepath.Base(cleanRepoRoot) |
| if statusWidth < statusHeaderWidth { | ||
| statusWidth = statusHeaderWidth | ||
| } | ||
|
|
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The calculation uses columnSpacingSlots (value 3) but it's not immediately clear why there are 3 spacing slots. Consider adding a comment explaining the layout: one spacing between PATH-BRANCH, one between BRANCH-STATUS, and one between STATUS-HEAD.
| // There are three spacing slots between the four columns: one between PATH-BRANCH, | |
| // one between BRANCH-STATUS, and one between STATUS-HEAD. |
cmd/wtp/init_test.go
Outdated
| originalWriteFile := writeFile | ||
| writeFile = func(string, []byte, os.FileMode) error { | ||
| return assert.AnError | ||
| } | ||
| defer func() { writeFile = originalWriteFile }() |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The mock function for writeFile is created but cmd.Action is called outside the test setup context where it's clear that a config file doesn't already exist. The test at line 207 should verify that the error message is meaningful, not just that an error occurred. Consider asserting the specific error type or message to ensure the failure path is correctly handled.
57b0351 to
b541ba4
Compare
Summary
Testing
Summary by CodeRabbit