I am trying to do a git pull using JGit\'s API with the following code
public class gitHubTest {
JSch jsch = new JSch();
// Defining the private key
I could figure out some of the issues I was facing. Here's solution to it:
if auth has to be done without the passphrase, generate the id_rsa without passphrase
We needed to override getJSch(final OpenSshConfig.Host hc, FS fs)
making use of addIdentity in the configure of SshSessionfactory:
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session sess ion) {
session.setConfig("StrictHostKeyChecking", "no");
}
@Override
protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException {
JSch jsch = super.getJSch(hc, fs);
jsch.removeAllIdentity();
jsch.addIdentity("/path/to/private/key");
return jsch;
}
};
We need to call needs to be instantiated differently:
PullCommand pull = git.pull().setTransportConfigCallback(new TransportConfigCallback() {
@Override
public void configure(Transport transport) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
}
});
And then call pull instance:
PullResult pullResult = pull.call();
I hope this helps.