*/
public class GitPackCommandTest {
@Test
public void testGitPack() throws Exception {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(8001);
sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setShellFactory(new EchoShellFactory());
sshd.setCommandFactory(new GitPackCommandFactory("target/git/server"));
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
sshd.start();
File serverDir = new File("target/git/server/test.git");
Utils.deleteRecursive(serverDir);
Git.init().setBare(true).setDirectory(serverDir).call();
JSch.setConfig("StrictHostKeyChecking", "no");
CredentialsProvider.setDefault(new UsernamePasswordCredentialsProvider("sshd", "sshd"));
GitSshdSessionFactory.setInstance(new GitSshdSessionFactory());
File dir = new File("target/git/local/test.git");
Utils.deleteRecursive(dir);
Git.cloneRepository()
.setURI("ssh://sshd@localhost:8001/test.git")
.setDirectory(dir)
.call();
Git git = Git.open(dir);
git.commit().setMessage("First Commit").setCommitter("sshd", "sshd@apache.org").call();
git.push().call();
new File("target/git/local/test.git/readme.txt").createNewFile();
git.add().addFilepattern("readme.txt").call();
git.commit().setMessage("readme").setCommitter("sshd", "sshd@apache.org").call();
git.push().call();
git.pull().setRebase(true).call();
sshd.stop();
}