我正在尝试使用JGit自动创建分支,检出,签入,提交和推送。
在运行以下代码时,出现以下异常。请帮助我了解造成此问题的原因。谢谢!
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.4.2.201908231537-r</version>
</dependency>
Added the below lib to resolve the ClassNotFound exception
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
import java.io.File;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
public class AutoCommit {
public static void main(String[] args){
try (Git git = Git.cloneRepository()
.setURI("https://<my repo>")
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("<username>", "<password>"))
.setBranch("feature/test")
.setDirectory(new File("C:\\workarea\\test"))
.call()) {
git.add().addFilepattern(".").call();
git.commit().setMessage("Testing the automated process").call();
git.status().call();
try {
git.push().setRemote("origin").add("feature/test").call();
} catch (TransportException e) {
System.out.println("Incorrect Username/Password");
}
}
catch(GitAPIException e) {
System.out.print(e);
}
}
}
这是异常堆栈跟踪
Exception in thread "main" java.lang.StackOverflowError
at java.util.HashMap.hash(Unknown Source)
at java.util.HashMap.get(Unknown Source)
at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:67)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:249)
at org.apache.log4j.Category.<init>(Category.java:57)
at org.apache.log4j.Logger.<init>(Logger.java:37)
at org.apache.log4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:43)
at org.apache.log4j.LogManager.getLogger(LogManager.java:45)
at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:249)
at org.apache.log4j.Category.<init>(Category.java:57)
at org.apache.log4j.Logger.<init>(Logger.java:37)