Skip to content

Commit a950867

Browse files
committed
fix: update test paths for new DefaultBaseDir and improve path handling
1 parent 6ff7489 commit a950867

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

cmd/wtp/remove_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func TestRemoveCommand_WorktreeNotFound_ShowsConsistentNames(t *testing.T) {
374374
results: []command.Result{
375375
{
376376
Output: "worktree /repo\nHEAD abc123\nbranch refs/heads/main\n\n" +
377-
"worktree /repo/.worktrees/feat/hogehoge\nHEAD def456\nbranch refs/heads/feat/hogehoge\n\n",
377+
"worktree /somewhere/else/feat/hogehoge\nHEAD def456\nbranch refs/heads/feat/hogehoge\n\n",
378378
Error: nil,
379379
},
380380
},
@@ -392,7 +392,7 @@ func TestRemoveCommand_WorktreeNotFound_ShowsConsistentNames(t *testing.T) {
392392
}
393393

394394
func TestRemoveCommand_FailsWhenRemovingCurrentWorktree(t *testing.T) {
395-
targetPath := "/worktrees/feature/foo"
395+
targetPath := "/worktrees/repo/feature/foo"
396396
mockWorktreeList := fmt.Sprintf(
397397
"worktree /repo\nHEAD abc123\nbranch refs/heads/main\n\n"+
398398
"worktree %s\nHEAD def456\nbranch refs/heads/feature/foo\n\n",

cmd/wtp/worktree_managed.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,23 @@ func isWorktreeManagedCommon(worktreePath string, cfg *config.Config, mainRepoPa
2626
baseDir := cfg.ResolveWorktreePath(mainRepoPath, "")
2727
baseDir = strings.TrimSuffix(baseDir, string(filepath.Separator))
2828

29-
absWorktreePath, err := filepath.Abs(worktreePath)
30-
if err != nil {
31-
return false
29+
// Convert to absolute paths only if they're not already absolute
30+
absWorktreePath := worktreePath
31+
if !filepath.IsAbs(worktreePath) {
32+
var err error
33+
absWorktreePath, err = filepath.Abs(worktreePath)
34+
if err != nil {
35+
return false
36+
}
3237
}
3338

34-
absBaseDir, err := filepath.Abs(baseDir)
35-
if err != nil {
36-
return false
39+
absBaseDir := baseDir
40+
if !filepath.IsAbs(baseDir) {
41+
var err error
42+
absBaseDir, err = filepath.Abs(baseDir)
43+
if err != nil {
44+
return false
45+
}
3746
}
3847

3948
relPath, err := filepath.Rel(absBaseDir, absWorktreePath)

0 commit comments

Comments
 (0)