List of usage examples for org.eclipse.jgit.api PushCommand setForce
public PushCommand setForce(boolean force)
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public PushResponse push(PushRequest request) throws GitException, UnauthorizedException { String remoteName = request.getRemote(); String remoteUri = getRepository().getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, remoteName, ConfigConstants.CONFIG_KEY_URL); PushResponse pushResponseDto = newDto(PushResponse.class); try {//from w w w . j a v a 2s . co m PushCommand pushCommand = getGit().push(); if (request.getRemote() != null) { pushCommand.setRemote(remoteName); } List<String> refSpec = request.getRefSpec(); if (!refSpec.isEmpty()) { List<RefSpec> refSpecInst = new ArrayList<>(refSpec.size()); refSpecInst.addAll(refSpec.stream().map(RefSpec::new).collect(Collectors.toList())); pushCommand.setRefSpecs(refSpecInst); } pushCommand.setForce(request.isForce()); int timeout = request.getTimeout(); if (timeout > 0) { pushCommand.setTimeout(timeout); } @SuppressWarnings("unchecked") Iterable<PushResult> pushResults = (Iterable<PushResult>) executeRemoteCommand(remoteUri, pushCommand); PushResult pushResult = pushResults.iterator().next(); return addCommandOutputUpdates(pushResponseDto, request, pushResult); } catch (GitAPIException exception) { if ("origin: not found.".equals(exception.getMessage())) { throw new GitException(ERROR_NO_REMOTE_REPOSITORY, exception); } else { throw new GitException(exception.getMessage(), exception); } } }
From source file:org.eclipse.orion.server.git.jobs.PushJob.java
License:Open Source License
private IStatus doPush() throws IOException, CoreException, URISyntaxException, GitAPIException { // /git/remote/{remote}/{branch}/file/{path} File gitDir = GitUtils.getGitDir(path.removeFirstSegments(2)); Repository db = new FileRepository(gitDir); Git git = new Git(db); PushCommand pushCommand = git.push(); RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote); credentials.setUri(remoteConfig.getURIs().get(0)); pushCommand.setCredentialsProvider(credentials); RefSpec spec = new RefSpec(srcRef + ':' + Constants.R_HEADS + branch); pushCommand.setRemote(remote).setRefSpecs(spec); if (tags)/* www .j av a 2 s. c om*/ pushCommand.setPushTags(); pushCommand.setForce(force); Iterable<PushResult> resultIterable = pushCommand.call(); PushResult pushResult = resultIterable.iterator().next(); // this set will contain only OK status or UP_TO_DATE status Set<RemoteRefUpdate.Status> statusSet = new HashSet<RemoteRefUpdate.Status>(); for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) { final String rm = rru.getRemoteName(); // check status only for branch given in the URL or tags if (branch.equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) { RemoteRefUpdate.Status status = rru.getStatus(); // any status different from UP_TO_DATE and OK should generate warning if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE) return new Status(IStatus.WARNING, GitActivator.PI_GIT, status.name(), new Throwable(rru.getMessage())); // add OK or UP_TO_DATE status to the set statusSet.add(status); } // TODO: return results for all updated branches once push is available for remote, see bug 352202 } if (statusSet.contains(RemoteRefUpdate.Status.OK)) // if there is OK status in the set -> something was updated return Status.OK_STATUS; else // if there is no OK status in the set -> only UP_TO_DATE status is possible return new Status(IStatus.WARNING, GitActivator.PI_GIT, RemoteRefUpdate.Status.UP_TO_DATE.name()); }
From source file:org.eclipse.orion.server.git.servlets.PushJob.java
License:Open Source License
private IStatus doPush() throws IOException, CoreException, JGitInternalException, InvalidRemoteException, URISyntaxException, JSONException { // /git/remote/{remote}/{branch}/file/{path} File gitDir = GitUtils.getGitDir(path.removeFirstSegments(2)); Repository db = new FileRepository(gitDir); Git git = new Git(db); PushCommand pushCommand = git.push(); RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), path.segment(0)); credentials.setUri(remoteConfig.getURIs().get(0)); pushCommand.setCredentialsProvider(credentials); // ObjectId ref = db.resolve(srcRef); RefSpec spec = new RefSpec(srcRef + ":" + Constants.R_HEADS + path.segment(1)); //$NON-NLS-1$ pushCommand.setRemote(path.segment(0)).setRefSpecs(spec); if (tags)/*from w w w . jav a 2s.c om*/ pushCommand.setPushTags(); pushCommand.setForce(force); Iterable<PushResult> resultIterable = pushCommand.call(); PushResult pushResult = resultIterable.iterator().next(); // this set will contain only OK status or UP_TO_DATE status Set<RemoteRefUpdate.Status> statusSet = new HashSet<RemoteRefUpdate.Status>(); for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) { final String rm = rru.getRemoteName(); // final String sr = rru.isDelete() ? null : rru.getSrcRef(); // check status only for branch given in the URL or tags if (path.segment(1).equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) { RemoteRefUpdate.Status status = rru.getStatus(); // any status different from UP_TO_DATE and OK should generate warning if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE) return new Status(IStatus.WARNING, GitActivator.PI_GIT, status.name()); // add OK or UP_TO_DATE status to the set statusSet.add(status); } // TODO: return results for all updated branches once push is available for remote, see bug 342727, comment 1 } if (statusSet.contains(RemoteRefUpdate.Status.OK)) // if there is OK status in the set -> something was updated return Status.OK_STATUS; else // if there is no OK status in the set -> only UP_TO_DATE status is possible return new Status(IStatus.WARNING, GitActivator.PI_GIT, RemoteRefUpdate.Status.UP_TO_DATE.name()); }
From source file:org.mule.module.git.GitConnector.java
License:Open Source License
/** * Update remote refs along with associated objects * * {@sample.xml ../../../doc/mule-module-git.xml.sample git:push} * * @param remote The remote (uri or name) used for the push operation. * @param force Sets the force preference for push operation * @param overrideDirectory Name of the directory to use for git repository *///from w w w . j a v a 2 s .com @Processor public void push(@Optional @Default("origin") String remote, @Optional @Default("false") boolean force, @Optional String overrideDirectory) { try { Git git = new Git(getGitRepo(overrideDirectory)); PushCommand push = git.push(); push.setRemote(remote); push.setForce(force); push.call(); } catch (Exception e) { throw new RuntimeException("Unable to push to " + remote, e); } }