Skip to content

Commit 1171e9f

Browse files
authored
Merge pull request #1215 from ahoppen/no-working-directory
Don’t use `workingDirectory` when creating a `SwiftPMDependencyProject`
2 parents bfe4e70 + 0ea9ae7 commit 1171e9f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Sources/SKTestSupport/SwiftPMDependencyProject.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ public class SwiftPMDependencyProject {
2525
/// The directory in which the repository lives.
2626
public let packageDirectory: URL
2727

28-
private func runCommand(_ toolName: String, _ arguments: [String], workingDirectory: URL) async throws {
28+
private func runGitCommand(_ arguments: [String], workingDirectory: URL) async throws {
2929
enum Error: Swift.Error {
30-
case cannotFindTool(toolName: String)
30+
case cannotFindGit
3131
case processedTerminatedWithNonZeroExitCode(ProcessResult)
3232
}
33-
guard let toolUrl = findTool(name: toolName) else {
33+
guard let toolUrl = findTool(name: "git") else {
3434
if ProcessEnv.block["SWIFTCI_USE_LOCAL_DEPS"] == nil {
3535
// Never skip the test in CI, similar to what SkipUnless does.
36-
throw XCTSkip("\(toolName) cannot be found")
36+
throw XCTSkip("git cannot be found")
3737
}
38-
throw Error.cannotFindTool(toolName: toolName)
38+
throw Error.cannotFindGit
3939
}
40-
print([toolUrl.path] + arguments)
40+
// We can't use `workingDirectory` because Amazon Linux doesn't support working directories (or at least
41+
// TSCBasic.Process doesn't support working directories on Amazon Linux)
4142
let process = TSCBasic.Process(
42-
arguments: [toolUrl.path] + arguments,
43-
workingDirectory: try AbsolutePath(validating: workingDirectory.path)
43+
arguments: [toolUrl.path, "-C", workingDirectory.path] + arguments
4444
)
4545
try process.launch()
4646
let processResult = try await process.waitUntilExit()
@@ -80,18 +80,16 @@ public class SwiftPMDependencyProject {
8080
try contents.write(to: fileURL, atomically: true, encoding: .utf8)
8181
}
8282

83-
try await runCommand("git", ["init"], workingDirectory: packageDirectory)
84-
try await runCommand(
85-
"git",
83+
try await runGitCommand(["init"], workingDirectory: packageDirectory)
84+
try await runGitCommand(
8685
["add"] + files.keys.map { $0.url(relativeTo: packageDirectory).path },
8786
workingDirectory: packageDirectory
8887
)
89-
try await runCommand(
90-
"git",
88+
try await runGitCommand(
9189
["-c", "user.name=Dummy", "-c", "[email protected]", "commit", "-m", "Initial commit"],
9290
workingDirectory: packageDirectory
9391
)
94-
try await runCommand("git", ["tag", "1.0.0"], workingDirectory: packageDirectory)
92+
try await runGitCommand(["tag", "1.0.0"], workingDirectory: packageDirectory)
9593
}
9694

9795
deinit {

0 commit comments

Comments
 (0)