@Test public void testPushToPushesRevision() throws IOException, GitAPIException { strategy.pushTo(repo, nodeConnection, REMOTE_PATH, revision); verify(pushCommand).setRefSpecs(new RefSpec() .setSource(REVISION) .setDestination("refs/commits/" + REVISION)); verify(pushCommand).setRemote("ssh: verify(pushCommand).call(); }
@Override public void pushTo(CodeRepo repo, NodeConnection node, String remotePath, CodeRevision revision) throws IOException { initRepository(node, remotePath); Git git = open(repo); RefSpec refspec = new RefSpec() .setSource(revision.getCommitId()) .setDestination("refs/commits/" + revision.getCommitId()); SshConfig sshConfig = node.getConnection().getConfig(); URI uri = sshConfig.toURIWithoutPassword().resolve("~/").resolve(remotePath); SshSessionFactory sshSessionFactory = new CustomSshConfigSessionFactory(sshConfig); CredentialsProvider credentialsProvider = null; if (!StringUtils.isEmpty(sshConfig.getPassword())) { credentialsProvider = new UsernamePasswordCredentialsProvider( sshConfig.getUser(), sshConfig.getPassword()); } try { git.push() .setRefSpecs(refspec) .setTransportConfigCallback(config -> ((TransportGitSsh) config).setSshSessionFactory(sshSessionFactory)) .setCredentialsProvider(credentialsProvider) .setRemote(uri.toString()) .call(); } catch (GitAPIException e) { throw new IOException(String.format("Unable to push %s at %s to %s", repo, revision, uri), e); } checkout(node, remotePath, revision); }
GitStrategy implements CodeRepoStrategy { @Override public void pushTo(CodeRepo repo, NodeConnection node, String remotePath, CodeRevision revision) throws IOException { initRepository(node, remotePath); Git git = open(repo); RefSpec refspec = new RefSpec() .setSource(revision.getCommitId()) .setDestination("refs/commits/" + revision.getCommitId()); SshConfig sshConfig = node.getConnection().getConfig(); URI uri = sshConfig.toURIWithoutPassword().resolve("~/").resolve(remotePath); SshSessionFactory sshSessionFactory = new CustomSshConfigSessionFactory(sshConfig); CredentialsProvider credentialsProvider = null; if (!StringUtils.isEmpty(sshConfig.getPassword())) { credentialsProvider = new UsernamePasswordCredentialsProvider( sshConfig.getUser(), sshConfig.getPassword()); } try { git.push() .setRefSpecs(refspec) .setTransportConfigCallback(config -> ((TransportGitSsh) config).setSshSessionFactory(sshSessionFactory)) .setCredentialsProvider(credentialsProvider) .setRemote(uri.toString()) .call(); } catch (GitAPIException e) { throw new IOException(String.format("Unable to push %s at %s to %s", repo, revision, uri), e); } checkout(node, remotePath, revision); } }
GitStrategy implements CodeRepoStrategy { @Override public void pushTo(CodeRepo repo, NodeConnection node, String remotePath, CodeRevision revision) throws IOException { initRepository(node, remotePath); Git git = open(repo); RefSpec refspec = new RefSpec() .setSource(revision.getCommitId()) .setDestination("refs/commits/" + revision.getCommitId()); SshConfig sshConfig = node.getConnection().getConfig(); URI uri = sshConfig.toURIWithoutPassword().resolve("~/").resolve(remotePath); SshSessionFactory sshSessionFactory = new CustomSshConfigSessionFactory(sshConfig); CredentialsProvider credentialsProvider = null; if (!StringUtils.isEmpty(sshConfig.getPassword())) { credentialsProvider = new UsernamePasswordCredentialsProvider( sshConfig.getUser(), sshConfig.getPassword()); } try { git.push() .setRefSpecs(refspec) .setTransportConfigCallback(config -> ((TransportGitSsh) config).setSshSessionFactory(sshSessionFactory)) .setCredentialsProvider(credentialsProvider) .setRemote(uri.toString()) .call(); } catch (GitAPIException e) { throw new IOException(String.format("Unable to push %s at %s to %s", repo, revision, uri), e); } checkout(node, remotePath, revision); } protected  GitStrategy(); }
GitStrategy implements CodeRepoStrategy { @Override public void pushTo(CodeRepo repo, NodeConnection node, String remotePath, CodeRevision revision) throws IOException { initRepository(node, remotePath); Git git = open(repo); RefSpec refspec = new RefSpec() .setSource(revision.getCommitId()) .setDestination("refs/commits/" + revision.getCommitId()); SshConfig sshConfig = node.getConnection().getConfig(); URI uri = sshConfig.toURIWithoutPassword().resolve("~/").resolve(remotePath); SshSessionFactory sshSessionFactory = new CustomSshConfigSessionFactory(sshConfig); CredentialsProvider credentialsProvider = null; if (!StringUtils.isEmpty(sshConfig.getPassword())) { credentialsProvider = new UsernamePasswordCredentialsProvider( sshConfig.getUser(), sshConfig.getPassword()); } try { git.push() .setRefSpecs(refspec) .setTransportConfigCallback(config -> ((TransportGitSsh) config).setSshSessionFactory(sshSessionFactory)) .setCredentialsProvider(credentialsProvider) .setRemote(uri.toString()) .call(); } catch (GitAPIException e) { throw new IOException(String.format("Unable to push %s at %s to %s", repo, revision, uri), e); } checkout(node, remotePath, revision); } protected  GitStrategy(); @Override void pushTo(CodeRepo repo, NodeConnection node, String remotePath, CodeRevision revision); void download(CodeRepo repo); @Override Stream<Commit> getCommits(CodeRepo repo); @Override CodeRevision getParentRevision(CodeRevision rev); List<LineChange> getDiff(CodeRevision oldest, CodeRevision newest); }
GitStrategy implements CodeRepoStrategy { @Override public void pushTo(CodeRepo repo, NodeConnection node, String remotePath, CodeRevision revision) throws IOException { initRepository(node, remotePath); Git git = open(repo); RefSpec refspec = new RefSpec() .setSource(revision.getCommitId()) .setDestination("refs/commits/" + revision.getCommitId()); SshConfig sshConfig = node.getConnection().getConfig(); URI uri = sshConfig.toURIWithoutPassword().resolve("~/").resolve(remotePath); SshSessionFactory sshSessionFactory = new CustomSshConfigSessionFactory(sshConfig); CredentialsProvider credentialsProvider = null; if (!StringUtils.isEmpty(sshConfig.getPassword())) { credentialsProvider = new UsernamePasswordCredentialsProvider( sshConfig.getUser(), sshConfig.getPassword()); } try { git.push() .setRefSpecs(refspec) .setTransportConfigCallback(config -> ((TransportGitSsh) config).setSshSessionFactory(sshSessionFactory)) .setCredentialsProvider(credentialsProvider) .setRemote(uri.toString()) .call(); } catch (GitAPIException e) { throw new IOException(String.format("Unable to push %s at %s to %s", repo, revision, uri), e); } checkout(node, remotePath, revision); } protected  GitStrategy(); @Override void pushTo(CodeRepo repo, NodeConnection node, String remotePath, CodeRevision revision); void download(CodeRepo repo); @Override Stream<Commit> getCommits(CodeRepo repo); @Override CodeRevision getParentRevision(CodeRevision rev); List<LineChange> getDiff(CodeRevision oldest, CodeRevision newest);  }