devvthedev opened a new issue, #532:
URL: https://github.com/apache/mina-sshd/issues/532

   Hello,
   
   I'm using the following JGit and Apache MINA dependencies in my project:
   ```
   implementation "org.eclipse.jgit:org.eclipse.jgit:6.10.0.202406032230-r"
   implementation 
"org.eclipse.jgit:org.eclipse.jgit.ssh.apache:6.10.0.202406032230-r"
   implementation "org.apache.sshd:sshd-git:2.13.1"
   ```
   
    I've created a default `org.apache.sshd.client.SshClient` with:
   `SshClient sshClient = SshClient.setUpDefaultClient();`
   
   and then set an instance of the GitSshdSessionFactory on JGits 
SshSessionFactory:
   `SshSessionFactory.setInstance(new GitSshdSessionFactory(sshClient));`
   
   <br>
   
   By default the sshClient is reading the SSH keys I have stored in the 
`~/.ssh` folder where the `config` file has the following configuration:
   ```
   Host github.com
     IdentityFile ~/.ssh/my-ssh-key
   ```
   
   I am using a **_passphrase-less_** private SSH key.
   
   <br>
   <br>
   
   The question I have is around JGits Git push command call when talking back 
to the remote repository.
   
   For example, 
   
   1. Given I have cloned a repository on my machine with SSH in a terminal:
   
   `git clone g...@github.com:devvthedev/my-project.git`
   
   2. Made some changes to the repo
   
   3. Opened the repo using JGit with `Git.open(...)` and get a `Git` object 
back
   
   4. Staged the changes I made and committed them:
   
   ```
   git.add()
       .addFilepattern(".")
       .call();
   ```
   
   ```
   git.commit()
       .setCommitter(new PersonIdent("me", "m...@example.com"))
       .setMessage("message")
       .call();
   ```
   
   6. When I try to push those changes with JGit:
   
   ```
   git.push()
       .call();
   ```
   
   I get the following error:
   
   ```
   Caused by: org.eclipse.jgit.errors.TransportException: Unable to connect
           at 
org.apache.sshd.git.transport.GitSshdSessionFactory.getSession(GitSshdSessionFactory.java:134)
           at 
org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:107)
           at 
org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:356)
           at 
org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:157)
           at 
org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:140)
           at org.eclipse.jgit.transport.Transport.push(Transport.java:1555)
           at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:158)
           ... 2 more
   Caused by: java.lang.NullPointerException: Cannot invoke 
"org.eclipse.jgit.transport.CredentialsProvider.isInteractive()" because 
"credentialsProvider" is null
           at 
org.apache.sshd.git.transport.GitSshdSession.<init>(GitSshdSession.java:55)
           at 
org.apache.sshd.git.transport.GitSshdSessionFactory$1.<init>(GitSshdSessionFactory.java:90)
           at 
org.apache.sshd.git.transport.GitSshdSessionFactory.getSession(GitSshdSessionFactory.java:90)
           ... 8 more
   ```
   
   <br>
   
   If I provide a CredentialsProvider with the `git` user and no password:
   
   ```
   git.push()
       .setCredentialsProvider(new UsernamePasswordCredentialsProvider("git", 
""))
       .call();
   ```
   
   It works!
   
   So my question is - why is a CredentialsProvider required given I have 
configured a `SshSessionFactory` instance?
   
   I've also raised this to JGit maintainers 
[here](https://github.com/eclipse-jgit/jgit/issues/72)
   
   Thank you
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to