@@ -157,6 +157,10 @@ func linkedWorktreeGitDirPath(fs afero.Fs, worktreePath string) (string, error)
157
157
}
158
158
159
159
gitDir := strings .TrimPrefix (gitDirLine [0 ], "gitdir: " )
160
+
161
+ // For windows support
162
+ gitDir = filepath .ToSlash (gitDir )
163
+
160
164
return gitDir , nil
161
165
}
162
166
@@ -194,19 +198,28 @@ func getCurrentRepoGitDirPath(
194
198
return "" , "" , errors .Errorf ("could not find git dir for %s: %v" , currentPath , err )
195
199
}
196
200
197
- // confirm whether the next directory up is the worktrees/submodules directory
201
+ _ , err = fs .Stat (worktreeGitPath )
202
+ if err != nil {
203
+ return "" , "" , errors .Errorf ("could not find git dir for %s: %v" , currentPath , err )
204
+ }
205
+
206
+ // confirm whether the next directory up is the worktrees directory
198
207
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 )
208
+ if path .Base (parent ) == "worktrees" {
209
+ gitDirPath := path .Dir (parent )
210
+ return gitDirPath , path .Dir (gitDirPath ), nil
201
211
}
202
212
203
- // if it's a submodule, we treat it as its own repo
204
- if path .Base (parent ) == "modules" {
213
+ // Unlike worktrees, submodules can be nested arbitrarily deep, so we check
214
+ // if the `modules` directory is anywhere up the chain.
215
+ if strings .Contains (worktreeGitPath , "/modules/" ) {
216
+ // For submodules, we just return the path directly
205
217
return worktreeGitPath , currentPath , nil
206
218
}
207
219
208
- gitDirPath := path .Dir (parent )
209
- return gitDirPath , path .Dir (gitDirPath ), nil
220
+ // If this error causes issues, we could relax the constraint and just always
221
+ // return the path
222
+ return "" , "" , errors .Errorf ("could not find git dir for %s: path is not under `worktrees` or `modules` directories" , currentPath )
210
223
}
211
224
212
225
// takes a path containing a symlink and returns the true path
0 commit comments