From 1bc4860f1a1ea77d80d4525645faa356c376f235 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sun, 19 Nov 2017 14:13:51 +0300 Subject: [PATCH] git tests: setup default username for auxiliary repositories Otherwise Git tries to get a username/email from the OS settings, which sometimes fail on test server agents, and it leads to commit failure. --- .../git4idea/tests/git4idea/repo/GitWorkTreeBaseTest.kt | 2 ++ plugins/git4idea/tests/git4idea/test/GitTestUtil.kt | 7 ++++--- plugins/git4idea/tests/git4idea/update/GitSubmoduleTest.kt | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/git4idea/tests/git4idea/repo/GitWorkTreeBaseTest.kt b/plugins/git4idea/tests/git4idea/repo/GitWorkTreeBaseTest.kt index c86f1653a5f6..300191ed9503 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitWorkTreeBaseTest.kt +++ b/plugins/git4idea/tests/git4idea/repo/GitWorkTreeBaseTest.kt @@ -23,6 +23,7 @@ import git4idea.config.GitVersion import git4idea.test.GitPlatformTest import git4idea.test.git import git4idea.test.registerRepo +import git4idea.test.setupDefaultUsername import org.junit.Assume.assumeTrue import java.io.File @@ -44,6 +45,7 @@ abstract class GitWorkTreeBaseTest : GitPlatformTest() { val gitDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(File(projectPath, GitUtil.DOT_GIT)) assertNotNull(gitDir) myRepo = registerRepo(project, projectPath) + setupDefaultUsername() assertEquals(1, repositoryManager.repositories.size) assertNotNull(repositoryManager.getRepositoryForRoot(projectRoot)) } diff --git a/plugins/git4idea/tests/git4idea/test/GitTestUtil.kt b/plugins/git4idea/tests/git4idea/test/GitTestUtil.kt index 6f4539ee0d74..cbe0d31a77c8 100644 --- a/plugins/git4idea/tests/git4idea/test/GitTestUtil.kt +++ b/plugins/git4idea/tests/git4idea/test/GitTestUtil.kt @@ -91,11 +91,12 @@ fun GitPlatformTest.cloneRepo(source: String, destination: String, bare: Boolean else { git("clone -- . $destination") } + cd(destination) + setupDefaultUsername() } -fun setupDefaultUsername(project: Project) { - setupUsername(project, USER_NAME, USER_EMAIL) -} +fun setupDefaultUsername(project: Project) = setupUsername(project, USER_NAME, USER_EMAIL) +fun GitPlatformTest.setupDefaultUsername() = setupDefaultUsername(project) fun setupUsername(project: Project, name: String, email: String) { assertFalse("Can not set empty user name ", name.isEmpty()) diff --git a/plugins/git4idea/tests/git4idea/update/GitSubmoduleTest.kt b/plugins/git4idea/tests/git4idea/update/GitSubmoduleTest.kt index c28e6e28154d..fc6a80bcd6e2 100644 --- a/plugins/git4idea/tests/git4idea/update/GitSubmoduleTest.kt +++ b/plugins/git4idea/tests/git4idea/update/GitSubmoduleTest.kt @@ -169,7 +169,7 @@ class GitSubmoduleTest : GitPlatformTest() { git("init $moduleName") val child = File(testRoot, moduleName) cd(child) - setupDefaultUsername(project) + setupDefaultUsername() tac("initial.txt", "initial") val parent = "$moduleName.git" git("remote add origin ${testRoot}/$parent") @@ -185,7 +185,10 @@ class GitSubmoduleTest : GitPlatformTest() { private fun prepareSecondClone(): File { cd(testRoot) git("clone --recurse-submodules parent.git bro") - return File(testRoot, "bro") + val broDir = File(testRoot, "bro") + cd(broDir) + setupDefaultUsername() + return broDir } private fun commitAndPushFromSecondClone(bro: File) {