Skip to content

Commit 36c222e

Browse files
authored
update submodules tests to set GIT_ALLOW_PROTOCOL = file (#5914)
motivation: Recent versions of git made a security fix to disallow the file transport by default. The GitRepository submodule test cases fail with these recent versions, because they use local submodules which rely on the file transport. changes: The GitRepositoryTests submodule tests set the environment variable GIT_ALLOW_PROTOCOL=file to tell git to allow use of the file protocol only for these tests where it's required. credit for this change to @dtweston
1 parent 5736a30 commit 36c222e

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Tests/SourceControlTests/GitRepositoryTests.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ import SPMTestSupport
2020
import enum TSCUtility.Git
2121

2222
class GitRepositoryTests: XCTestCase {
23+
24+
override func setUp() {
25+
// needed for submodule tests
26+
Git.environment = ["GIT_ALLOW_PROTOCOL": "file"]
27+
}
28+
29+
override func tearDown() {
30+
Git.environment = ProcessInfo.processInfo.environment
31+
}
32+
2333
/// Test the basic provider functions.
2434
func testRepositorySpecifier() {
2535
do {
@@ -184,7 +194,9 @@ class GitRepositoryTests: XCTestCase {
184194
initGitRepo(repoPath)
185195

186196
try Process.checkNonZeroExit(
187-
args: Git.tool, "-C", repoPath.pathString, "submodule", "add", testRepoPath.pathString)
197+
args: Git.tool, "-C", repoPath.pathString, "submodule", "add", testRepoPath.pathString,
198+
environment: Git.environment
199+
)
188200
let repo = GitRepository(path: repoPath)
189201
try repo.stageEverything()
190202
try repo.commit()
@@ -571,7 +583,11 @@ class GitRepositoryTests: XCTestCase {
571583

572584
// Add submodule to foo and tag it as 1.0.1
573585
try foo.checkout(newBranch: "submodule")
574-
try systemQuietly([Git.tool, "-C", fooPath.pathString, "submodule", "add", barPath.pathString, "bar"])
586+
try Process.checkNonZeroExit(
587+
args: Git.tool, "-C", fooPath.pathString, "submodule", "add", barPath.pathString, "bar",
588+
environment: Git.environment
589+
)
590+
575591
try foo.stageEverything()
576592
try foo.commit()
577593
try foo.tag(name: "1.0.1")
@@ -589,7 +605,11 @@ class GitRepositoryTests: XCTestCase {
589605
// Add something to bar.
590606
try localFileSystem.writeFileContents(barPath.appending(component: "bar.txt"), bytes: "hello")
591607
// Add a submodule too to check for recursive submodules.
592-
try systemQuietly([Git.tool, "-C", barPath.pathString, "submodule", "add", bazPath.pathString, "baz"])
608+
try Process.checkNonZeroExit(
609+
args: Git.tool, "-C", barPath.pathString, "submodule", "add", bazPath.pathString, "baz",
610+
environment: Git.environment
611+
)
612+
593613
try bar.stageEverything()
594614
try bar.commit()
595615

0 commit comments

Comments
 (0)