/** * Add a reference to push. * * @param nameOrSpec * any reference name, or a reference specification. * @return {@code this}. * @throws JGitInternalException * the reference name cannot be resolved. */ public PushCommand add(String nameOrSpec) { if (0 <= nameOrSpec.indexOf(':')) { refSpecs.add(new RefSpec(nameOrSpec)); } else { Ref src; try { src = repo.findRef(nameOrSpec); } catch (IOException e) { throw new JGitInternalException( JGitText.get().exceptionCaughtDuringExecutionOfPushCommand, e); } if (src != null) add(src); } return this; }
PushCommand pushCommand = git.push(); pushCommand.setForce( true ); pushCommand.add( "refs/*:refs/*" );
/** * Add a reference to push. * * @param nameOrSpec * any reference name, or a reference specification. * @return {@code this}. * @throws JGitInternalException * the reference name cannot be resolved. */ public PushCommand add(String nameOrSpec) { if (0 <= nameOrSpec.indexOf(':')) { refSpecs.add(new RefSpec(nameOrSpec)); } else { Ref src; try { src = repo.findRef(nameOrSpec); } catch (IOException e) { throw new JGitInternalException( JGitText.get().exceptionCaughtDuringExecutionOfPushCommand, e); } if (src != null) add(src); } return this; }
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(); } }
/** * Add a reference to push. * * @param nameOrSpec * any reference name, or a reference specification. * @return {@code this}. * @throws JGitInternalException * the reference name cannot be resolved. */ public PushCommand add(String nameOrSpec) { if (0 <= nameOrSpec.indexOf(':')) { refSpecs.add(new RefSpec(nameOrSpec)); } else { Ref src; try { src = repo.findRef(nameOrSpec); } catch (IOException e) { throw new JGitInternalException( JGitText.get().exceptionCaughtDuringExecutionOfPushCommand, e); } if (src != null) add(src); } return this; }
public boolean newRemoteBranch(String branchName) throws Exception { try{ log.info("Purging branches that no longer have remotes."); git.fetch().setRemoveDeletedRefs(true).call(); } catch(Exception e) { log.warn("Tried to fetch from remote when there is no remote."); return false; } boolean branchExists = checkForRemoteBranch(branchName); if(!branchExists) { Ref ref = newLocalBranch(branchName); git.push().add(ref).call(); return true; } else { log.info(branchName + " already exists."); } return false; }
public boolean newEmtpyRemoteBranch(String branchName) throws Exception { try{ log.info("Purging branches that no longer have remotes."); git.fetch().setRemoveDeletedRefs(true).call(); } catch(Exception e) { log.warn("Tried to fetch from remote when there is no remote."); return false; } boolean branchExists = checkForRemoteBranch(branchName); if(!branchExists) { Ref ref = newEmptyLocalBranch(branchName); git.push().add(ref).call(); return true; } else { log.info(branchName + " already exists."); } return false; }
@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(); }
try (Git git = new Git(repository)) { RevCommit commit = git.commit().setMessage(comment).call(); Iterable<PushResult> results = git.push().setRemote(REMOTE).add(LOCAL_BRANCH) .call(); List<Status> statuses = StreamSupport.stream(results.spliterator(), false)
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); }
/** * @inheritDoc */ @Override public Iterable<PushResult> push(Git git, String username, String password, String reference, String remote, boolean force) { UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password); try { Iterable<PushResult> results = git .push() .setCredentialsProvider(credentialsProvider) .add(reference) .setRemote(remote) .setForce(force) .call(); for(PushResult result : results){ RemoteRefUpdate update = result.getRemoteUpdate(reference); RemoteRefUpdate.Status status = update.getStatus(); if(!(status.equals(RemoteRefUpdate.Status.OK)||status.equals(RemoteRefUpdate.Status.UP_TO_DATE))){ throw new RuntimeException("Failed to push changes to origin"); } } return results; } catch (GitAPIException e) { throw new RuntimeException("Failed to push to origin", e); } }
/** * @inheritDoc */ @Override public boolean deleteTag(Git git, String tag, String username, String password){ Ref tagRef = git.getRepository().getTags().get(tag); if(tagRef != null){ try { //delete remote tag, if UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password); git.push() .setCredentialsProvider(credentialsProvider) .add(":"+tagRef) .setRemote("upstream") .call(); git.tagDelete().setTags(tagRef.getName()).call(); return true; } catch (GitAPIException e) { throw new RuntimeException("Failed to delete tag "+tag, e); } } else { return false; } }
Ref branch = git.checkout().setCreateBranch(true).setName(branchName).call(); git.push().setRemote(REMOTE_NAME).add(branch).setCredentialsProvider(credentialsProvider).call();
remoteAddCommand.call(); git.push().add(branchName).setRemote("fork-patch").setCredentialsProvider(new UsernamePasswordCredentialsProvider(RepairnatorConfig.getInstance().getGithubToken(), "")).call();