This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new accf5818f7f Camel-git: fix environmental contamination and default branch for tests (#8632) accf5818f7f is described below commit accf5818f7fe77d418d02bb9cd563bbba324b813 Author: Gilvan Filho <gilvan.sfi...@gmail.com> AuthorDate: Thu Oct 27 01:59:05 2022 -0300 Camel-git: fix environmental contamination and default branch for tests (#8632) * camel-git: avoid environmental contamination on tests * camel-git: set master as default branch for tests --- .../java/org/apache/camel/component/git/GitTestSupport.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java b/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java index 3dd1f95d28a..70df54bc373 100644 --- a/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java +++ b/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java @@ -22,9 +22,11 @@ import java.io.IOException; import org.apache.camel.test.junit5.CamelTestSupport; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.util.SystemReader; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -69,9 +71,11 @@ public class GitTestSupport extends CamelTestSupport { deleteDirectory(path); } - protected Repository getTestRepository() throws IOException, IllegalStateException, GitAPIException { + protected Repository getTestRepository() + throws IOException, IllegalStateException, GitAPIException, ConfigInvalidException { File gitRepo = new File(gitLocalRepo, ".git"); - Git.init().setDirectory(new File(gitLocalRepo, "")).setBare(false).call(); + SystemReader.getInstance().getUserConfig().clear(); //clears user config in JGit context, that way there are no environmental contamination that may affect the tests + Git.init().setDirectory(new File(gitLocalRepo, "")).setInitialBranch("master").setBare(false).call(); // now open the resulting repository with a FileRepositoryBuilder FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repo = builder.setGitDir(gitRepo).readEnvironment() // scan @@ -83,7 +87,7 @@ public class GitTestSupport extends CamelTestSupport { return repo; } - protected Git getGitTestRepository() throws IOException, IllegalStateException, GitAPIException { + protected Git getGitTestRepository() throws IOException, IllegalStateException, GitAPIException, ConfigInvalidException { return new Git(getTestRepository()); }