org.eclipse.jgit.api.PushCommand Java Examples

The following examples show how to use org.eclipse.jgit.api.PushCommand. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitHubNotebookRepo.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
private void pushToRemoteSteam() {
  try {
    LOG.debug("Pushing latest changes to remote stream");
    PushCommand pushCommand = git.push();
    pushCommand.setCredentialsProvider(
      new UsernamePasswordCredentialsProvider(
        zeppelinConfiguration.getZeppelinNotebookGitUsername(),
        zeppelinConfiguration.getZeppelinNotebookGitAccessToken()
      )
    );

    pushCommand.call();
  } catch (GitAPIException e) {
    LOG.error("Error when pushing latest changes to remote repository", e);
  }
}
 
Example #2
Source File: ConfigurationExporter.java    From opsgenie-configuration-backup with Apache License 2.0 6 votes vote down vote up
/**
 * This is main export method. This method export opsgenie configuration to local folder. If git
 * is enabled from BackupProperties parameters it will export those configurations to remote
 * git.
 */
void export() throws GitAPIException, InterruptedException, IOException {
    if (getBackupProperties().isGitEnabled()) {
        cloneGit(getBackupProperties());
    }
    init();
    logger.info("Export operation started!");
    for (final Exporter exporter : exporters) {
        exporter.export();
    }

    if (getBackupProperties().isGitEnabled()) {
        logger.info("Export to remote git operation started!");
        getGit().add().addFilepattern("OpsGenieBackups").call();
        getGit().commit().setAll(true).setAllowEmpty(true).setMessage("Opsgenie Backups").setCommitter("opsgenie", "[email protected]").call();
        PushCommand pc = getGit().push();
        pc.setTransportConfigCallback(getCallBack());
        pc.setForce(true).setPushAll();
        pc.call();
        logger.info("Export to remote git operation finished!");
    }
    logger.info("Export operation finished!");
}
 
Example #3
Source File: OldGitHubNotebookRepo.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
private void pushToRemoteSteam() {
  try {
    LOG.debug("Pushing latest changes to remote stream");
    PushCommand pushCommand = git.push();
    pushCommand.setCredentialsProvider(
      new UsernamePasswordCredentialsProvider(
        zeppelinConfiguration.getZeppelinNotebookGitUsername(),
        zeppelinConfiguration.getZeppelinNotebookGitAccessToken()
      )
    );

    pushCommand.call();
  } catch (GitAPIException e) {
    LOG.error("Error when pushing latest changes to remote repository", e);
  }
}
 
Example #4
Source File: GitHubConnector.java    From tool.accelerate.core with Apache License 2.0 5 votes vote down vote up
/**
 * Must be called after #{createGitRepository()}
 */
public void pushAllChangesToGit() throws IOException {
    if (localRepository == null) {
        throw new IOException("Git has not been created, call createGitRepositoryFirst");
    }
    try {
        UserService userService = new UserService();
        userService.getClient().setOAuth2Token(oAuthToken);
        User user = userService.getUser();
        String name = user.getLogin();
        String email = user.getEmail();
        if (email == null) {
            // This is the e-mail addressed used by GitHub on web commits where the users mail is private. See:
            // https://github.com/settings/emails
            email = name + "@users.noreply.github.com";
        }

        localRepository.add().addFilepattern(".").call();
        localRepository.commit()
                .setMessage("Initial commit")
                .setCommitter(name, email)
                .call();
        PushCommand pushCommand = localRepository.push();
        addAuth(pushCommand);
        pushCommand.call();
    } catch (GitAPIException e) {
        throw new IOException("Error pushing changes to GitHub", e);
    }
}
 
Example #5
Source File: GitUtils.java    From blueocean-plugin with MIT License 5 votes vote down vote up
/**
 *  Attempts to push to a non-existent branch to validate the user actually has push access
 *
 * @param repo local repository
 * @param remoteUrl git repo url
 * @param credential credential to use when accessing git
 */
public static void validatePushAccess(@Nonnull Repository repo, @Nonnull String remoteUrl, @Nullable StandardCredentials credential) throws GitException {
    try (org.eclipse.jgit.api.Git git = new org.eclipse.jgit.api.Git(repo)) {
        // we need to perform an actual push, so we try a deletion of a very-unlikely-to-exist branch
        // which needs to have push permissions in order to get a 'branch not found' message
        String pushSpec = ":this-branch-is-only-to-test-if-jenkins-has-push-access";
        PushCommand pushCommand = git.push();

        addCredential(repo, pushCommand, credential);

        Iterable<PushResult> resultIterable = pushCommand
            .setRefSpecs(new RefSpec(pushSpec))
            .setRemote(remoteUrl)
            .setDryRun(true) // we only want to test
            .call();
        PushResult result = resultIterable.iterator().next();
        if (result.getRemoteUpdates().isEmpty()) {
            System.out.println("No remote updates occurred");
        } else {
            for (RemoteRefUpdate update : result.getRemoteUpdates()) {
                if (!RemoteRefUpdate.Status.NON_EXISTING.equals(update.getStatus()) && !RemoteRefUpdate.Status.OK.equals(update.getStatus())) {
                    throw new ServiceException.UnexpectedErrorException("Expected non-existent ref but got: " + update.getStatus().name() + ": " + update.getMessage());
                }
            }
        }
    } catch (GitAPIException e) {
        if (e.getMessage().toLowerCase().contains("auth")) {
            throw new ServiceException.UnauthorizedException(e.getMessage(), e);
        }
        throw new ServiceException.UnexpectedErrorException("Unable to access and push to: " + remoteUrl + " - " + e.getMessage(), e);
    }
}
 
Example #6
Source File: GitUtils.java    From blueocean-plugin with MIT License 5 votes vote down vote up
public static void push(String remoteUrl, Repository repo, StandardCredentials credential, String localBranchRef, String remoteBranchRef) {
    try (org.eclipse.jgit.api.Git git = new org.eclipse.jgit.api.Git(repo)) {
        String pushSpec = "+" + localBranchRef + ":" + remoteBranchRef;
        PushCommand pushCommand = git.push();

        addCredential(repo, pushCommand, credential);

        Iterable<PushResult> resultIterable = pushCommand
            .setRefSpecs(new RefSpec(pushSpec))
            .setRemote(remoteUrl)
            .call();
        PushResult result = resultIterable.iterator().next();
        if (result.getRemoteUpdates().isEmpty()) {
            throw new RuntimeException("No remote updates occurred");
        } else {
            for (RemoteRefUpdate update : result.getRemoteUpdates()) {
                if (!RemoteRefUpdate.Status.OK.equals(update.getStatus())) {
                    throw new ServiceException.UnexpectedErrorException("Remote update failed: " + update.getStatus().name() + ": " + update.getMessage());
                }
            }
        }
    } catch (GitAPIException e) {
        if (e.getMessage().toLowerCase().contains("auth")) {
            throw new ServiceException.UnauthorizedException(e.getMessage(), e);
        }
        throw new ServiceException.UnexpectedErrorException("Unable to save and push to: " + remoteUrl + " - " + e.getMessage(), e);
    }
}
 
Example #7
Source File: GitCatalogDao.java    From logging-log4j-audit with Apache License 2.0 5 votes vote down vote up
@Override
public void write(CatalogData data) {
    File localRepoFile = new File(localRepoPath);
    if (!localRepoFile.exists() || !localRepoFile.canWrite()) {
        throw new CatalogModificationException("Catalog is not writable: " + localRepoFile.getAbsolutePath());
    }

    try (FileWriter writer = new FileWriter(catalogFile)){
        String text = mapper.writeValueAsString(data);
        writer.write(text);
    } catch (IOException ioException) {
        throw new CatalogModificationException("Unable to write catalog file.", ioException);
    }

    try (Git git = Git.open(localRepoFile)) {
        git.add().addFilepattern(catalogPath).call();
        git.commit().setMessage("Catalog updated").call();
        updateRepo();
        PushCommand pushCommand = git.push();
        if (credentialsProvider != null) {
            pushCommand.setCredentialsProvider(credentialsProvider);
        }
        if (transportConfigCallback != null) {
            pushCommand.setTransportConfigCallback(transportConfigCallback);
        }
        pushCommand.call();
    } catch (GitAPIException | IOException ex) {
        throw new CatalogModificationException("Unable to modify catalog", ex);
    }
}
 
Example #8
Source File: AppraiseGitReviewClient.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Pushes the local comments and reviews back to the origin.
 */
private void pushCommentsAndReviews() throws Exception {
  try (Git git = new Git(repo)) {
    RefSpec spec = new RefSpec(DEVTOOLS_PUSH_REFSPEC);
    PushCommand pushCommand = git.push();
    pushCommand.setRefSpecs(spec);
    pushCommand.call();
  }
}
 
Example #9
Source File: GitControl.java    From juneau with Apache License 2.0 5 votes vote down vote up
public void pushToRepo() throws IOException, JGitInternalException, InvalidRemoteException, GitAPIException {
	PushCommand pc = git.push();
	pc.setCredentialsProvider(cp).setForce(true).setPushAll();
	try {
		Iterator<PushResult> it = pc.call().iterator();
		if (it.hasNext()) {
			System.out.println(it.next().toString());
		}
	} catch (InvalidRemoteException e) {
		e.printStackTrace();
	}
}
 
Example #10
Source File: LocalGitRepo.java    From multi-module-maven-release-plugin with MIT License 5 votes vote down vote up
@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();
}
 
Example #11
Source File: PushTask.java    From ant-git-tasks with Apache License 2.0 4 votes vote down vote up
@Override
protected void doExecute() {
        try {
                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));

                PushCommand pushCommand = git.push().
                        setPushAll().
                        setRefSpecs(specs).
                        setDryRun(false).
                        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) {
                        GitTaskUtils.validateTrackingRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getTrackingRefUpdates());
                        log(pushResult.getMessages());
                }
        } catch (Exception e) {
                if (pushFailedProperty != null) {
                        getProject().setProperty(pushFailedProperty, e.getMessage());
                }

                throw new GitBuildException(PUSH_FAILED_MESSAGE, e);
        }
}
 
Example #12
Source File: GitWithAuth.java    From centraldogma with Apache License 2.0 4 votes vote down vote up
@Override
public PushCommand push() {
    return configure(super.push()).setProgressMonitor(progressMonitor("push"));
}
 
Example #13
Source File: CommitPush.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(Wandora wandora, Context context) {

    try {
        Git git = getGit();    
        if(git != null) {
            if(isNotEmpty(getGitRemoteUrl())) {
                if(commitPushUI == null) {
                    commitPushUI = new CommitPushUI();
                }

                commitPushUI.setPassword(getPassword());
                commitPushUI.setUsername(getUsername());
                commitPushUI.openInDialog();

                if(commitPushUI.wasAccepted()) {
                    setDefaultLogger();
                    setLogTitle("Git commit and push");

                    saveWandoraProject();

                    log("Removing deleted files from local repository.");
                    org.eclipse.jgit.api.Status status = git.status().call();
                    Set<String> missing = status.getMissing();
                    if(missing != null && !missing.isEmpty()) {
                        for(String missingFile : missing) {
                            git.rm()
                                    .addFilepattern(missingFile)
                                    .call();
                        }
                    }

                    log("Adding new files to the local repository.");
                    git.add()
                            .addFilepattern(".")
                            .call();

                    log("Committing changes to the local repository.");
                    String commitMessage = commitPushUI.getMessage();
                    if(commitMessage == null || commitMessage.length() == 0) {
                        commitMessage = getDefaultCommitMessage();
                        log("No commit message provided. Using default message.");
                    }
                    git.commit()
                            .setMessage(commitMessage)
                            .call();

                    String username = commitPushUI.getUsername();
                    String password = commitPushUI.getPassword();

                    setUsername(username);
                    setPassword(password);

                    PushCommand push = git.push();
                    if(isNotEmpty(username)) {
                        log("Setting push credentials.");
                        CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( username, password );
                        push.setCredentialsProvider(credentialsProvider);
                    }
                    log("Pushing upstream.");
                    push.call();

                    log("Ready.");
                }
            }
            else {
                log("Repository has no remote origin and can't be pushed. " 
                        + "Commit changes to the local repository using Commit to local... "
                        + "To push changes to a remote repository initialize repository by cloning.");
            }
        }
        else {
            logAboutMissingGitRepository();
        }
    }
    catch(GitAPIException gae) {
        log(gae.toString());
    }
    catch(NoWorkTreeException nwte) {
        log(nwte.toString());
    }
    catch(IOException ioe) {
        log(ioe.toString());
    }
    catch(TopicMapException tme) {
        log(tme.toString());
    }
    catch(Exception e) {
        log(e);
    }
    setState(WAIT);
}
 
Example #14
Source File: Push.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(Wandora wandora, Context context) {
    
    try {
        Git git = getGit();
        if(git != null) {
            if(isNotEmpty(getGitRemoteUrl())) {
                if(pushUI == null) {
                    pushUI = new PushUI();
                }

                pushUI.setPassword(getPassword());
                pushUI.setUsername(getUsername());
                pushUI.setRemoteUrl(getGitRemoteUrl());
                pushUI.openInDialog();

                if(pushUI.wasAccepted()) {
                    setDefaultLogger();
                    setLogTitle("Git push");

                    String username = pushUI.getUsername();
                    String password = pushUI.getPassword();
                    String remoteUrl = pushUI.getRemoteUrl();

                    setUsername(username);
                    setPassword(password);
                    // setGitRemoteUrl(remoteUrl);

                    PushCommand push = git.push();

                    log("Pushing local changes to upstream.");
                    if(username != null && username.length() > 0) {
                        CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( username, password );
                        push.setCredentialsProvider(credentialsProvider);
                    }

                    Iterable<PushResult> pushResults = push.call();

                    for(PushResult pushResult : pushResults) {
                        String pushResultMessage = pushResult.getMessages();
                        if(isNotEmpty(pushResultMessage)) {
                            log(pushResultMessage);
                        }
                    }
                    log("Ready.");
                }
            }
            else {
                log("Repository has no remote origin and can't be pushed. " 
                    +"Initialize repository by cloning remote repository to set the remote origin.");
            }
        }
        else {
            logAboutMissingGitRepository();
        }
    }
    catch(TransportException tre) {
        if(tre.toString().contains("origin: not found.")) {
            log("Git remote origin is not found. Check the remote url and remote git repository.");
        }
    }
    catch(GitAPIException gae) {
        log(gae.toString());
    }
    catch(NoWorkTreeException nwte) {
        log(nwte.toString());
    }
    catch(Exception e) {
        log(e);
    }
    setState(WAIT);
}
 
Example #15
Source File: JGitOperator.java    From verigreen with Apache License 2.0 4 votes vote down vote up
@Override
public boolean push(String sourceBranch, String destinationBranch) {
       
       PushCommand command = _git.push();
       boolean ret = true;
       RefSpec refSpec = new RefSpec().setSourceDestination(sourceBranch, destinationBranch);
       command.setRefSpecs(refSpec);
       try {
       	List<Ref> remoteBranches = _git.branchList().setListMode(ListMode.REMOTE).call();
           if(_cp != null)
               command.setCredentialsProvider(_cp);
           Iterable<PushResult> results = command.call();
           for (PushResult pushResult : results) {
           	Collection<RemoteRefUpdate> resultsCollection = pushResult.getRemoteUpdates();
           	Map<PushResult,RemoteRefUpdate> resultsMap = new HashMap<>();
           	for(RemoteRefUpdate remoteRefUpdate : resultsCollection)
           	{
           		resultsMap.put(pushResult, remoteRefUpdate);
           	}
           	
               RemoteRefUpdate remoteUpdate = pushResult.getRemoteUpdate(destinationBranch);
               if (remoteUpdate != null) {
                   org.eclipse.jgit.transport.RemoteRefUpdate.Status status =
                           remoteUpdate.getStatus();
                   ret =
                           status.equals(org.eclipse.jgit.transport.RemoteRefUpdate.Status.OK)
                                   || status.equals(org.eclipse.jgit.transport.RemoteRefUpdate.Status.UP_TO_DATE);
               }
               
               if(remoteUpdate == null && !remoteBranches.toString().contains(destinationBranch))
               {	
            
               	
               	for(RemoteRefUpdate resultValue : resultsMap.values())
               	{
               		if(resultValue.toString().contains("REJECTED_OTHER_REASON"))
               		{
               			ret = false;
               		}
               	}
               }	
           }
       } catch (Throwable e) {
           throw new RuntimeException(String.format(
                   "Failed to push [%s] into [%s]",
                   sourceBranch,
                   destinationBranch), e);
       }
       
       return ret;
   }
 
Example #16
Source File: Config.java    From github-bucket with ISC License 4 votes vote down vote up
default PushCommand configure(PushCommand cmd) {
    return cmd;
}
 
Example #17
Source File: GitRepo.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
PushCommand push(Git git) {
	return git.push().setCredentialsProvider(this.provider)
			.setTransportConfigCallback(this.callback);
}
 
Example #18
Source File: RepositoryResource.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
protected Iterable<PushResult> doPush(Git git) throws Exception {
    PushCommand command = git.push();
    configureCommand(command, userDetails);
    return command.setRemote(getRemote()).call();
}
 
Example #19
Source File: ForgeTestSupport.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
protected Build assertCodeChangeTriggersWorkingBuild(final String projectName, Build firstBuild) throws Exception {
    File cloneDir = new File(getBasedir(), "target/projects/" + projectName);

    String gitUrl = asserGetAppGitCloneURL(forgeClient, projectName);
    Git git = ForgeClientAsserts.assertGitCloneRepo(gitUrl, cloneDir);

    // lets make a dummy commit...
    File readme = new File(cloneDir, "ReadMe.md");
    boolean mustAdd = false;
    String text = "";
    if (readme.exists()) {
        text = IOHelpers.readFully(readme);
    } else {
        mustAdd = true;
    }
    text += "\nupdated at: " + new Date();
    Files.writeToFile(readme, text, Charset.defaultCharset());

    if (mustAdd) {
        AddCommand add = git.add().addFilepattern("*").addFilepattern(".");
        add.call();
    }


    LOG.info("Committing change to " + readme);

    CommitCommand commit = git.commit().setAll(true).setAuthor(forgeClient.getPersonIdent()).setMessage("dummy commit to trigger a rebuild");
    commit.call();
    PushCommand command = git.push();
    command.setCredentialsProvider(forgeClient.createCredentialsProvider());
    command.setRemote("origin").call();

    LOG.info("Git pushed change to " + readme);

    // now lets wait for the next build to start
    int nextBuildNumber = firstBuild.getNumber() + 1;


    Asserts.assertWaitFor(10 * 60 * 1000, new Block() {
        @Override
        public void invoke() throws Exception {
            JobWithDetails job = assertJob(projectName);
            Build lastBuild = job.getLastBuild();
            assertThat(lastBuild.getNumber()).describedAs("Waiting for latest build for job " + projectName + " to start").isGreaterThanOrEqualTo(nextBuildNumber);
        }
    });

    return ForgeClientAsserts.assertBuildCompletes(forgeClient, projectName);
}
 
Example #20
Source File: Config.java    From github-bucket with ISC License 4 votes vote down vote up
default PushCommand configure(PushCommand cmd) {
    return cmd;
}
 
Example #21
Source File: PushJob.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
private IStatus doPush(IProgressMonitor monitor) throws IOException, CoreException, URISyntaxException, GitAPIException {
	ProgressMonitor gitMonitor = new EclipseGitProgressTransformer(monitor);
	// /git/remote/{remote}/{branch}/file/{path}
	File gitDir = GitUtils.getGitDir(path.removeFirstSegments(2));
	Repository db = null;
	JSONObject result = new JSONObject();
	try {
		db = FileRepositoryBuilder.create(gitDir);
		Git git = Git.wrap(db);

		PushCommand pushCommand = git.push();
		pushCommand.setProgressMonitor(gitMonitor);
		pushCommand.setTransportConfigCallback(new TransportConfigCallback() {
			@Override
			public void configure(Transport t) {
				credentials.setUri(t.getURI());
				if (t instanceof TransportHttp && cookie != null) {
					HashMap<String, String> map = new HashMap<String, String>();
					map.put(GitConstants.KEY_COOKIE, cookie.getName() + "=" + cookie.getValue());
					((TransportHttp) t).setAdditionalHeaders(map);
				}
			}
		});
		RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote);
		credentials.setUri(remoteConfig.getURIs().get(0));
		pushCommand.setCredentialsProvider(credentials);

		boolean pushToGerrit = branch.startsWith("for/");
		RefSpec spec = new RefSpec(srcRef + ':' + (pushToGerrit ? "refs/" : Constants.R_HEADS) + branch);
		pushCommand.setRemote(remote).setRefSpecs(spec);
		if (tags)
			pushCommand.setPushTags();
		pushCommand.setForce(force);
		Iterable<PushResult> resultIterable = pushCommand.call();
		if (monitor.isCanceled()) {
			return new Status(IStatus.CANCEL, GitActivator.PI_GIT, "Cancelled");
		}
		PushResult pushResult = resultIterable.iterator().next();
		boolean error = false;
		JSONArray updates = new JSONArray();
		result.put(GitConstants.KEY_COMMIT_MESSAGE, pushResult.getMessages());
		result.put(GitConstants.KEY_UPDATES, updates);
		for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) {
			if (monitor.isCanceled()) {
				return new Status(IStatus.CANCEL, GitActivator.PI_GIT, "Cancelled");
			}
			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) || rm.startsWith(Constants.R_REFS + "for/")) {
				JSONObject object = new JSONObject();
				RemoteRefUpdate.Status status = rru.getStatus();
				if (status != RemoteRefUpdate.Status.UP_TO_DATE || !rm.startsWith(Constants.R_TAGS)) {
					object.put(GitConstants.KEY_COMMIT_MESSAGE, rru.getMessage());
					object.put(GitConstants.KEY_RESULT, status.name());
					TrackingRefUpdate refUpdate = rru.getTrackingRefUpdate();
					if (refUpdate != null) {
						object.put(GitConstants.KEY_REMOTENAME, Repository.shortenRefName(refUpdate.getLocalName()));
						object.put(GitConstants.KEY_LOCALNAME, Repository.shortenRefName(refUpdate.getRemoteName()));
					} else {
						object.put(GitConstants.KEY_REMOTENAME, Repository.shortenRefName(rru.getSrcRef()));
						object.put(GitConstants.KEY_LOCALNAME, Repository.shortenRefName(rru.getRemoteName()));
					}
					updates.put(object);
				}
				if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE)
					error = true;
			}
			// TODO: return results for all updated branches once push is available for remote, see bug 352202
		}
		// needs to handle multiple
		result.put("Severity", error ? "Error" : "Ok");
	} catch (JSONException e) {
	} finally {
		if (db != null) {
			db.close();
		}
	}
	return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
}
 
Example #22
Source File: GitRepo.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
PushCommand push(Git git) {
	return git.push().setCredentialsProvider(this.provider)
			.setTransportConfigCallback(this.callback);
}