Auth example
Garf1eldGit opened this issue · comments
Garf1eldGit commented
Please add an authentication example to the git repository. Without this, there is no point in using the library.
I'm trying to clone a repository and I'm getting an error "unresolved reference"
In general, I just don’t understand what needs to be done to authenticate using this library.
val git: KGit = KGit.cloneRepository {
setURI("ssh://git@stash.com:7999/project/reponame.git")
setBranchesToClone(listOf("refs/heads/develop"))
setBranch("refs/heads/develop")
setCredentialsProvider(UsernamePasswordCredentialsProvider("user", "password"))
setTransportConfigCallback { transport ->
val sshTransport = transport as? SshTransport
sshTransport?.sshSessionFactory = sshSessionFactory;
}
var sshSessionFactory: SshSessionFactory =
object : org.gradle.internal.impldep.org.eclipse.jgit.transport.JschConfigSessionFactory() { <<-- unresolved reference
protected fun configure(host: Host?, session: Session?) {
// do nothing
}
}
}
sya-ri commented
I haven't maintained this library for a long time, so I'm sorry for not replying.
KGit is just a wrapper for JGit basic features, and to do that you need to add the necessary jgit libraries as dependencies.
build.gradle.kts
dependencies {
implementation("org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:$jgitVersion")
}
Source
/*
* import com.jcraft.jsch.Session
* import org.eclipse.jgit.transport.SshTransport
* import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
* import org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory
* import org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig
*/
val git: KGit = KGit.cloneRepository {
setURI("ssh://git@stash.com:7999/project/reponame.git")
setBranchesToClone(listOf("refs/heads/develop"))
setBranch("refs/heads/develop")
setCredentialsProvider(UsernamePasswordCredentialsProvider("user", "password"))
setTransportConfigCallback { transport ->
val sshTransport = transport as? SshTransport
sshTransport?.sshSessionFactory =
object : JschConfigSessionFactory() {
override fun configure(host: OpenSshConfig.Host?, session: Session?) {
// do nothing
}
}
}
}
I haven't tried running it, but at least it shouldn't cause any build errors.