File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ public enum Environment {
6969 return nil
7070 }
7171
72+ #warning("TODO: Use WorkspaceXcodeWindowInspector.extractProjectURL instead.")
7273 public static var guessProjectRootURLForFile : ( _ fileURL: URL ) async throws -> URL = {
7374 fileURL in
7475 var currentURL = fileURL
@@ -77,10 +78,19 @@ public enum Environment {
7778 while currentURL. pathComponents. count > 1 {
7879 defer { currentURL. deleteLastPathComponent ( ) }
7980 guard FileManager . default. fileIsDirectory ( atPath: currentURL. path) else { continue }
81+ guard currentURL. pathExtension != " xcodeproj " else { continue }
82+ guard currentURL. pathExtension != " xcworkspace " else { continue }
83+ guard currentURL. pathExtension != " playground " else { continue }
8084 if firstDirectoryURL == nil { firstDirectoryURL = currentURL }
8185 let gitURL = currentURL. appendingPathComponent ( " .git " )
8286 if FileManager . default. fileIsDirectory ( atPath: gitURL. path) {
8387 lastGitDirectoryURL = currentURL
88+ } else if let text = try ? String ( contentsOf: gitURL) {
89+ if !text. hasPrefix ( " gitdir: ../ " ) , // it's not a sub module
90+ text. range ( of: " /.git/worktrees/ " ) != nil // it's a git worktree
91+ {
92+ lastGitDirectoryURL = currentURL
93+ }
8494 }
8595 }
8696
Original file line number Diff line number Diff line change @@ -115,10 +115,19 @@ public final class WorkspaceXcodeWindowInspector: XcodeWindowInspector {
115115 while currentURL. pathComponents. count > 1 {
116116 defer { currentURL. deleteLastPathComponent ( ) }
117117 guard FileManager . default. fileIsDirectory ( atPath: currentURL. path) else { continue }
118+ guard currentURL. pathExtension != " xcodeproj " else { continue }
119+ guard currentURL. pathExtension != " xcworkspace " else { continue }
120+ guard currentURL. pathExtension != " playground " else { continue }
118121 if firstDirectoryURL == nil { firstDirectoryURL = currentURL }
119122 let gitURL = currentURL. appendingPathComponent ( " .git " )
120123 if FileManager . default. fileIsDirectory ( atPath: gitURL. path) {
121124 lastGitDirectoryURL = currentURL
125+ } else if let text = try ? String ( contentsOf: gitURL) {
126+ if !text. hasPrefix ( " gitdir: ../ " ) , // it's not a sub module
127+ text. range ( of: " /.git/worktrees/ " ) != nil // it's a git worktree
128+ {
129+ lastGitDirectoryURL = currentURL
130+ }
122131 }
123132 }
124133
You can’t perform that action at this time.
0 commit comments