@@ -67,6 +67,61 @@ Deno.test({
67
67
sanitizeOps : false ,
68
68
} ) ;
69
69
70
+ Deno . test ( {
71
+ name : "findWorktree() returns a root path for worktree inside .git directory" ,
72
+ fn : async ( ) => {
73
+ await using sbox = await prepare ( ) ;
74
+ // Create a worktree inside .git/workspaces/ directory
75
+ await Deno . mkdir ( join ( ".git" , "workspaces" ) , { recursive : true } ) ;
76
+ await $ `git worktree add -b workspace-test .git/workspaces/test main` ;
77
+
78
+ // Change to a subdirectory within the worktree
79
+ await Deno . mkdir ( join ( ".git" , "workspaces" , "test" , "subdir" ) , {
80
+ recursive : true ,
81
+ } ) ;
82
+ Deno . chdir ( join ( ".git" , "workspaces" , "test" , "subdir" ) ) ;
83
+
84
+ // findWorktree should return the worktree root, not the main repository root
85
+ assertEquals (
86
+ await findWorktree ( "." ) ,
87
+ join ( sbox . path , ".git" , "workspaces" , "test" ) ,
88
+ ) ;
89
+ // An internal cache will be used for the following call
90
+ assertEquals (
91
+ await findWorktree ( "." ) ,
92
+ join ( sbox . path , ".git" , "workspaces" , "test" ) ,
93
+ ) ;
94
+ } ,
95
+ sanitizeResources : false ,
96
+ sanitizeOps : false ,
97
+ } ) ;
98
+
99
+ Deno . test ( {
100
+ name : "findGitdir() returns a gitdir path for worktree inside .git directory" ,
101
+ fn : async ( ) => {
102
+ await using sbox = await prepare ( ) ;
103
+ // Create a worktree inside .git/workspaces/ directory
104
+ await Deno . mkdir ( join ( ".git" , "workspaces" ) , { recursive : true } ) ;
105
+ await $ `git worktree add -b workspace-test2 .git/workspaces/test2 main` ;
106
+
107
+ // Change to the worktree
108
+ Deno . chdir ( join ( ".git" , "workspaces" , "test2" ) ) ;
109
+
110
+ // findGitdir should return the correct gitdir for this worktree
111
+ assertEquals (
112
+ await findGitdir ( "." ) ,
113
+ join ( sbox . path , ".git" , "worktrees" , "test2" ) ,
114
+ ) ;
115
+ // An internal cache will be used for the following call
116
+ assertEquals (
117
+ await findGitdir ( "." ) ,
118
+ join ( sbox . path , ".git" , "worktrees" , "test2" ) ,
119
+ ) ;
120
+ } ,
121
+ sanitizeResources : false ,
122
+ sanitizeOps : false ,
123
+ } ) ;
124
+
70
125
Deno . test ( {
71
126
name :
72
127
"findGitdir() throws an error if the path is not in a git working directory" ,
0 commit comments