push.setCredentialsProvider(credentialsProvider); push.setCredentialsProvider(new UsernamePasswordCredentialsProvider( credentials.valueOfIndex("username").toString(), credentials.valueOfIndex("password").toString()
public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException { Repository repository = repositoryService.createRepository(new Repository().setName(applicationName)); String cloneUrl = repository.getCloneUrl(); InitCommand init = new InitCommand(); init.setDirectory(srcFolder); init.setBare(false); Git git = init.call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", cloneUrl); config.save(); UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, ""); git.add().addFilepattern(".").call(); git.commit().setMessage(COMMIT_MESSAGE).call(); git.push().setCredentialsProvider(user).call(); return repository; } }
public void push() throws Exception { PushCommand push = git.push(); if (credentialsProvider != null) push.setCredentialsProvider(credentialsProvider); push.call(); }
PushCommand push(Git git) { return git.push().setCredentialsProvider(this.provider) .setTransportConfigCallback(this.callback); }
private void push() throws GitAPIException { Lock writeLock = repositoryLock.writeLock(); try { writeLock.lock(); PushCommand push = git.push().setPushTags().add(branch); if (StringUtils.isNotBlank(login)) { push.setCredentialsProvider(new UsernamePasswordCredentialsProvider(login, password)); } push.call(); monitor.fireOnChange(); } finally { writeLock.unlock(); } }
/** * Pushes the artifacts of the tenant to relevant remote repository * * @param gitRepoCtx RepositoryContext instance for the tenant */ private void pushToRemoteRepo(RepositoryContext gitRepoCtx) { PushCommand pushCmd = gitRepoCtx.getGit().push(); if (!gitRepoCtx.getKeyBasedAuthentication()) { UsernamePasswordCredentialsProvider credentialsProvider = createCredentialsProvider(gitRepoCtx); if (credentialsProvider != null) pushCmd.setCredentialsProvider(credentialsProvider); } try { pushCmd.call(); if (log.isDebugEnabled()) { log.debug("Pushed artifacts for tenant : " + gitRepoCtx.getTenantId()); } } catch (GitAPIException e) { log.error("Pushing artifacts to remote repository failed for tenant " + gitRepoCtx.getTenantId(), e); } }
public Iterable<PushResult> forcePush(Git git, String login, String password) throws GitAPIException { val result = git.push() .setCredentialsProvider(new UsernamePasswordCredentialsProvider(login, password)) .setForce(true) .call(); logPushResultDetails(result); return result; }
@Override public void pushTags(Collection<AnnotatedTag> tags) throws GitAPIException { PushCommand pushCommand = git.push() .setCredentialsProvider(credentialsProvider); if (remoteUrl != null) { pushCommand.setRemote(remoteUrl); } for (AnnotatedTag tag : tags) { pushCommand.add(tag.saveAtHEAD(git)); } pushCommand.call(); }
@Override protected Iterable<PushResult> doPush(Git git) throws Exception { return this.git.push().setCredentialsProvider(getCredentials()).setRemote(getRemote()).call(); }
protected RevCommit doCommitAndPush(Git git, String message, CredentialsProvider credentials, PersonIdent author, String remote, String branch) throws IOException, GitAPIException { CommitCommand commit = git.commit().setAll(true).setMessage(message); if (author != null) { commit = commit.setAuthor(author); } RevCommit answer = commit.call(); if (LOG.isDebugEnabled()) { LOG.debug("Committed " + answer.getId() + " " + answer.getFullMessage()); } if (isPushOnCommit()) { Iterable<PushResult> results = git.push().setCredentialsProvider(credentials).setRemote(remote).call(); for (PushResult result : results) { if (LOG.isDebugEnabled()) { LOG.debug("Pushed " + result.getMessages() + " " + result.getURI() + " branch: " + branch + " updates: " + GitHelpers.toString(result.getRemoteUpdates())); } } } return answer; }
public Void call(Git git, GitContext context) throws Exception { removeVersionFromCaches(versionId); GitHelpers.removeBranch(git, versionId); git.push().setTimeout(gitTimeout) .setCredentialsProvider(getCredentialsProvider()) .setRefSpecs(new RefSpec().setSource(null).setDestination("refs/heads/" + versionId)) .call(); return null; } };
public Void call(Git git, GitContext context) throws Exception { removeVersionFromCaches(versionId); GitHelpers.removeBranch(git, versionId); git.push().setTimeout(gitTimeout) .setCredentialsProvider(getCredentialsProvider()) .setRefSpecs(new RefSpec().setSource(null).setDestination("refs/heads/" + versionId)) .call(); return null; } };
public void execute() throws InvalidRemoteException { try { final List<RefSpec> specs = new UpdateRemoteConfig(git, remote, refSpecs).execute(); git._push() .setCredentialsProvider(credentialsProvider) .setRefSpecs(specs) .setRemote(remote.getK1()) .setForce(force) .setPushAll() .call(); } catch (final InvalidRemoteException e) { throw e; } catch (final Exception ex) { throw new RuntimeException(ex); } } }
public void stageAndPushDeletedFile() { try { Git git = this.gitOpen(gitDir); git.add().addFilepattern(".").setUpdate(true).call(); git.commit().setMessage("wipe").call(); PushCommand command = git.push().setForce(true); command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); command.call(); } catch (GitAPIException e) { log.error(e.getMessage(), e); } }
/** * Pull-rebase and push to the remote repo if git.remote is enabled * * @throws GitAPIException If there is a failure talking to the remote repository */ public void push() throws GitAPIException { if (remote) { synchronized (gitDir) { if (haveRemoteBranch()) { git.pull().setCredentialsProvider(provider).setRebase(true).call(); } git.push().setCredentialsProvider(provider).setRemote("origin").call(); } } }
protected void doPushTag(Exchange exchange, String operation) throws Exception { Iterable<PushResult> result = null; try { if (ObjectHelper.isEmpty(endpoint.getRemoteName())) { throw new IllegalArgumentException("Remote name must be specified to execute " + operation); } if (ObjectHelper.isEmpty(endpoint.getTagName())) { throw new IllegalArgumentException("Tag Name must be specified to execute " + operation); } if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) { UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword()); result = git.push().setCredentialsProvider(credentials).setRemote(endpoint.getRemoteName()).add(Constants.R_TAGS + endpoint.getTagName()).call(); } else { result = git.push().setRemote(endpoint.getRemoteName()).add(Constants.R_TAGS + endpoint.getTagName()).call(); } } catch (Exception e) { LOG.error("There was an error in Git {} operation", operation); throw e; } updateExchange(exchange, result); }
public static Iterable<PushResult> push( ScmLogger logger, Git git, GitScmProviderRepository repo, RefSpec refSpec ) throws GitAPIException, InvalidRemoteException, TransportException { CredentialsProvider credentials = JGitUtils.prepareSession( logger, git, repo ); Iterable<PushResult> pushResultList = git.push().setCredentialsProvider( credentials ).setRefSpecs( refSpec ).call(); for ( PushResult pushResult : pushResultList ) { Collection<RemoteRefUpdate> ru = pushResult.getRemoteUpdates(); for ( RemoteRefUpdate remoteRefUpdate : ru ) { logger.info( remoteRefUpdate.getStatus() + " - " + remoteRefUpdate.toString() ); } } return pushResultList; }
public void pushRepo(String uri, GitUser user) { try { setRemote(uri); git.push().setRemote(REMOTE_NAME).setCredentialsProvider(new UsernamePasswordCredentialsProvider(user.getUsername(), user.getPassword())).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } }
public void doAddCommitPush() throws IOException, GitAPIException { Git git = gitOpen(); gitOpen().add() .addFilepattern(".") .call(); git.commit() .setMessage("Automatic commit by releasetrain") .call(); git.push() .setCredentialsProvider(credentialsProvider()) .call(); }
public static Iterable<PushResult> push( ScmLogger logger, Git git, GitScmProviderRepository repo, RefSpec refSpec ) throws GitAPIException, InvalidRemoteException, TransportException { CredentialsProvider credentials = JGitUtils.prepareSession( logger, git, repo ); PushCommand command = git.push().setRefSpecs(refSpec).setCredentialsProvider(credentials) .setTransportConfigCallback(new JGitTransportConfigCallback(repo, logger)); Iterable<PushResult> pushResultList = command.call(); for ( PushResult pushResult : pushResultList ) { Collection<RemoteRefUpdate> ru = pushResult.getRemoteUpdates(); for ( RemoteRefUpdate remoteRefUpdate : ru ) { logger.info( remoteRefUpdate.getStatus() + " - " + remoteRefUpdate.toString() ); } } return pushResultList; }