@@ -23,45 +23,7 @@ var removeGetwd = os.Getwd
2323
2424// isWorktreeManaged determines if a worktree is managed by wtp
2525func isWorktreeManaged (worktreePath string , cfg * config.Config , mainRepoPath string , isMain bool ) bool {
26- // Main worktree is always managed
27- if isMain {
28- return true
29- }
30-
31- // Get base directory - use default config if config is not available
32- if cfg == nil {
33- // Create default config when none is available
34- defaultCfg := & config.Config {
35- Defaults : config.Defaults {
36- BaseDir : "../worktrees" ,
37- },
38- }
39- cfg = defaultCfg
40- }
41-
42- baseDir := cfg .ResolveWorktreePath (mainRepoPath , "" )
43- // Remove trailing slash if it exists
44- baseDir = strings .TrimSuffix (baseDir , "/" )
45-
46- // Check if worktree path is under base directory
47- absWorktreePath , err := filepath .Abs (worktreePath )
48- if err != nil {
49- return false
50- }
51-
52- absBaseDir , err := filepath .Abs (baseDir )
53- if err != nil {
54- return false
55- }
56-
57- // Check if worktree is within base directory
58- relPath , err := filepath .Rel (absBaseDir , absWorktreePath )
59- if err != nil {
60- return false
61- }
62-
63- // If relative path starts with "..", it's outside base directory
64- return ! strings .HasPrefix (relPath , ".." )
26+ return isWorktreeManagedCommon (worktreePath , cfg , mainRepoPath , isMain )
6527}
6628
6729// NewRemoveCommand creates the remove command definition
@@ -163,7 +125,7 @@ func removeCommandWithCommandExecutor(
163125 return errors .DirectoryAccessFailed ("access current" , cwd , err )
164126 }
165127
166- if isPathWithin (absCwd , absTargetPath ) {
128+ if isPathWithin (absTargetPath , absCwd ) {
167129 return errors .CannotRemoveCurrentWorktree (worktreeName , absTargetPath )
168130 }
169131
0 commit comments