@@ -194,19 +194,28 @@ func getCurrentRepoGitDirPath(
194
194
return "" , "" , errors .Errorf ("could not find git dir for %s: %v" , currentPath , err )
195
195
}
196
196
197
- // confirm whether the next directory up is the worktrees/submodules directory
197
+ _ , err = fs .Stat (worktreeGitPath )
198
+ if err != nil {
199
+ return "" , "" , errors .Errorf ("could not find git dir for %s: %v" , currentPath , err )
200
+ }
201
+
202
+ // confirm whether the next directory up is the worktrees directory
198
203
parent := path .Dir (worktreeGitPath )
199
- if path .Base (parent ) != "worktrees" && path .Base (parent ) != "modules" {
200
- return "" , "" , errors .Errorf ("could not find git dir for %s" , currentPath )
204
+ if path .Base (parent ) == "worktrees" {
205
+ gitDirPath := path .Dir (parent )
206
+ return gitDirPath , path .Dir (gitDirPath ), nil
201
207
}
202
208
203
- // if it's a submodule, we treat it as its own repo
204
- if path .Base (parent ) == "modules" {
209
+ // Unlike worktrees, submodules can be nested arbitrarily deep, so we check
210
+ // if the `modules` directory is anywhere up the chain.
211
+ if strings .Contains (worktreeGitPath , "/modules/" ) {
212
+ // For submodules, we just return the path directly
205
213
return worktreeGitPath , currentPath , nil
206
214
}
207
215
208
- gitDirPath := path .Dir (parent )
209
- return gitDirPath , path .Dir (gitDirPath ), nil
216
+ // If this error causes issues, we could relax the constraint and just always
217
+ // return the path
218
+ return "" , "" , errors .Errorf ("could not find git dir for %s: path is not under `worktrees` or `modules` directories" , currentPath )
210
219
}
211
220
212
221
// takes a path containing a symlink and returns the true path
0 commit comments