-
-
Save ederign/7326e16c8adcdd5724e0da5b812af1fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS org.eclipse.jgit:org.eclipse.jgit:5.4.0.201906121030-r | |
//DEPS org.slf4j:slf4j-nop:1.7.31 | |
package me.porcelli.jgit; | |
import com.jcraft.jsch.*; | |
import org.eclipse.jgit.api.CloneCommand; | |
import org.eclipse.jgit.api.Git; | |
import org.eclipse.jgit.transport.JschConfigSessionFactory; | |
import org.eclipse.jgit.transport.SshTransport; | |
import org.eclipse.jgit.transport.OpenSshConfig; | |
import org.eclipse.jgit.util.FS; | |
public class jbang { | |
public static void main(String... args) throws Exception { | |
CloneCommand cloneCommand = Git.cloneRepository(); | |
cloneCommand.setURI( args[0] ); | |
cloneCommand.setTransportConfigCallback(transport -> { | |
final SshTransport sshTransport = (SshTransport) transport; | |
sshTransport.setSshSessionFactory(new JschConfigSessionFactory() { | |
@Override | |
protected void configure(OpenSshConfig.Host host, Session session) {} | |
@Override | |
protected JSch createDefaultJSch(FS fs) throws JSchException { | |
JSch defaultJSch = super.createDefaultJSch( fs ); | |
defaultJSch.addIdentity( "/path/to/private_key" ); | |
return defaultJSch; | |
} | |
}); | |
}); | |
cloneCommand.call(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment