List of usage examples for org.eclipse.jgit.api PushCommand setPushTags
public PushCommand setPushTags()
From source file:com.google.gerrit.acceptance.git.GitUtil.java
License:Apache License
public static PushResult pushHead(Git git, String ref, boolean pushTags) throws GitAPIException { PushCommand pushCmd = git.push(); pushCmd.setRefSpecs(new RefSpec("HEAD:" + ref)); if (pushTags) { pushCmd.setPushTags(); }/*from w w w .ja v a 2s.co m*/ Iterable<PushResult> r = pushCmd.call(); return Iterables.getOnlyElement(r); }
From source file:com.google.gerrit.acceptance.GitUtil.java
License:Apache License
public static PushResult pushHead(TestRepository<?> testRepo, String ref, boolean pushTags, boolean force) throws GitAPIException { PushCommand pushCmd = testRepo.git().push(); pushCmd.setForce(force);/* www. ja va 2 s.c om*/ pushCmd.setRefSpecs(new RefSpec("HEAD:" + ref)); if (pushTags) { pushCmd.setPushTags(); } Iterable<PushResult> r = pushCmd.call(); return Iterables.getOnlyElement(r); }
From source file:com.meltmedia.cadmium.core.git.GitService.java
License:Apache License
public void push(boolean tags) throws Exception { PushCommand push = git.push(); if (tags) {//w ww .jav a 2s . c o m push.setPushTags(); } push.call(); }
From source file:com.rimerosolutions.ant.git.tasks.PushTask.java
License:Apache License
@Override protected void doExecute() { try {//from ww w . j a v a 2 s . co m StoredConfig config = git.getRepository().getConfig(); List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config); if (remoteConfigs.isEmpty()) { URIish uri = new URIish(getUri()); RemoteConfig remoteConfig = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME); remoteConfig.addURI(uri); remoteConfig.addFetchRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.addPushRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.update(config); config.save(); } String currentBranch = git.getRepository().getBranch(); List<RefSpec> specs = Arrays.asList(new RefSpec(currentBranch + ":" + currentBranch)); if (deleteRemoteBranch != null) { specs = Arrays.asList(new RefSpec(":" + Constants.R_HEADS + deleteRemoteBranch)); } PushCommand pushCommand = git.push().setPushAll().setRefSpecs(specs).setDryRun(false); if (getUri() != null) { pushCommand.setRemote(getUri()); } setupCredentials(pushCommand); if (includeTags) { pushCommand.setPushTags(); } if (getProgressMonitor() != null) { pushCommand.setProgressMonitor(getProgressMonitor()); } Iterable<PushResult> pushResults = pushCommand.setForce(true).call(); for (PushResult pushResult : pushResults) { log(pushResult.getMessages()); GitTaskUtils.validateRemoteRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getRemoteUpdates()); GitTaskUtils.validateTrackingRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getTrackingRefUpdates()); } } catch (Exception e) { if (pushFailedProperty != null) { getProject().setProperty(pushFailedProperty, e.getMessage()); } throw new GitBuildException(PUSH_FAILED_MESSAGE, e); } }
From source file:org.ajoberstar.gradle.git.tasks.GitPush.java
License:Apache License
/** * Pushes changes to a remote repository. *///from w ww . ja va2 s .c om @TaskAction public void push() { PushCommand cmd = getGit().push(); TransportAuthUtil.configure(cmd, this); cmd.setRemote(getRemote()); if (isPushTags()) { cmd.setPushTags(); } if (isPushAll()) { cmd.setPushAll(); } cmd.setForce(isForce()); try { cmd.call(); } catch (Exception e) { throw new GradleException("Problem pushing to repository.", e); } //TODO add progress monitor to go to Gradle status bar }
From source file:org.codehaus.mojo.versions.BumpMojo.java
License:Apache License
void gitPush(String o, String d) throws MojoExecutionException { try {/*from w ww.j a v a 2 s. co m*/ RefSpec spec = new RefSpec(d + ":" + d); PushCommand ff = git.push(); ff.setRemote(o); ff.setRefSpecs(spec); ff.setPushTags(); Iterable<PushResult> f = ff.call(); } catch (GitAPIException e) { throw new MojoExecutionException(e.getMessage(), e); } }
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.jav a2 s .co m 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. j a v a2 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(); // 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()); }