Skip to content

Commit 266a491

Browse files
authored
Fix Git discovery & execution on Windows (#96)
This fixes: * git discovery by searching for `git.exe` instead of `git` * git invocation by passing an absolute path instead of just an executable name For an example of usage please see `GitRepositoryProvider.fetch` in the SwiftPM project.
1 parent f4df3ff commit 266a491

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Sources/TSCBasic/Process.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,15 @@ public final class Process: ObjectIdentifierProtocol {
340340
}
341341

342342
// Look for executable.
343-
guard Process.findExecutable(arguments[0]) != nil else {
344-
throw Process.Error.missingExecutableProgram(program: arguments[0])
343+
let executable = arguments[0]
344+
guard let executablePath = Process.findExecutable(executable) else {
345+
throw Process.Error.missingExecutableProgram(program: executable)
345346
}
346347

347348
#if os(Windows)
348349
_process = Foundation.Process()
349350
_process?.arguments = Array(arguments.dropFirst()) // Avoid including the executable URL twice.
350-
_process?.executableURL = URL(fileURLWithPath: arguments[0])
351+
_process?.executableURL = executablePath.asURL
351352
_process?.environment = environment
352353

353354
if outputRedirection.redirectsOutput {

Sources/TSCBasic/misc.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
import TSCLibc
1212
import Foundation
1313

14+
#if os(Windows)
15+
public let executableFileSuffix = ".exe"
16+
#else
17+
public let executableFileSuffix = ""
18+
#endif
19+
1420
/// Replace the current process image with a new process image.
1521
///
1622
/// - Parameters:

Sources/TSCUtility/Git.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class Git {
5757
}
5858

5959
/// A shell command to run for Git. Can be either a name or a path.
60-
public static var tool: String = "git"
60+
public static var tool: String = "git\(executableFileSuffix)"
6161

6262
/// Returns true if the git reference name is well formed.
6363
public static func checkRefFormat(ref: String) -> Bool {

0 commit comments

Comments
 (0)