String getMergedConfig(String branchName, RevCommit newCommit) throws GitAPIException, IOException { MergeResult result = null; try { checkout(branchName); result = git.merge().include(newCommit).call(); } catch (GitAPIException e) { LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); throw e; } if (!result.getMergeStatus().isSuccessful()) { LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed as config file has changed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); throw new ConfigFileHasChangedException(); } LOGGER.info("[CONFIG_MERGE] Successfully merged commit {} by user {} to branch {}. Merge commit revision is {}", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); return FileUtils.readFileToString(new File(workingDir, CRUISE_CONFIG_XML), UTF_8); }
private MergeResult merge(Git git, String label) { try { MergeCommand merge = git.merge(); merge.include(git.getRepository().findRef("origin/" + label)); MergeResult result = merge.call(); if (!result.getMergeStatus().isSuccessful()) { this.logger.warn("Merged from remote " + label + " with result " + result.getMergeStatus()); } return result; } catch (Exception ex) { String message = "Could not merge remote for " + label + " remote: " + git .getRepository().getConfig().getString("remote", "origin", "url"); warn(message, ex); return null; } }
@Signature public Memory merge(String[] refs, ArrayMemory settings) throws IOException, GitAPIException { MergeCommand command = getWrappedObject().merge(); for (String ref : refs) { Repository repository = getWrappedObject().getRepository(); ObjectId objectId = repository.resolve(ref); command.include(objectId); } if (settings != null) { command.setCommit(settings.valueOfIndex("commit").toBoolean()); command.setMessage(settings.valueOfIndex("message").toString()); command.setSquash(settings.valueOfIndex("squash").toBoolean()); Memory fastForward = settings.valueOfIndex("fastForward"); if (fastForward.isNumber()) { command.setFastForward(MergeCommand.FastForwardMode.valueOf(fastForward.toString())); } Memory strategy = settings.valueOfIndex("strategy"); if (strategy.isNotNull()) { command.setStrategy(MergeStrategy.get(strategy.toString())); } } MergeResult call = command.call(); return GitUtils.valueOf(call); }
MergeResult merge = git.merge(). include(mergeBase). setCommit(true).
MergeResult merge = git.merge(). include(mergeBase). setCommit(true).
MergeCommand merge = git.merge() .setFastForward(MergeCommand.FastForwardMode.NO_FF) .setProgressMonitor(monitor)
/** * Merge with temporary branch * @param git * @param newBranchFull * @throws IOException * @throws GitAPIException */ private void mergeWithNewBranch(Git git, String newBranchFull) throws Exception { MergeCommand mergeCommand = git.merge(); try { mergeCommand.include(git.getRepository().getRef(newBranchFull)); mergeCommand.setFastForward(MergeCommand.FastForwardMode.FF_ONLY); mergeCommand.call(); } catch (GitAPIException e) { throw new Exception(MERGING_PROBLEM_REASON, e); } catch (IOException e) { throw new Exception(GIT_COMMAND_REASON, e); } }
Git git = ... // you get it through a CloneCommand, InitCommand // or through the file system CheckoutCommand coCmd = git.checkout(); // Commands are part of the api module, which include git-like calls coCmd.setName("master"); coCmd.setCreateBranch(false); // probably not needed, just to make sure coCmd.call(); // switch to "master" branch MergeCommand mgCmd = git.merge(); mgCmd.include("foo"); // "foo" is considered as a Ref to a branch MergeResult res = mgCmd.call(); // actually do the merge if (res.getMergeStatus().equals(MergeResult.MergeStatus.CONFLICTING)){ System.out.println(res.getConflicts().toString()); // inform the user he has to handle the conflicts }
/** * Merges the branch represented by the passed branchId in the current branch. * * @param branchId - String representation of an ObjectId * @throws GitAPIException - failed. */ public void merge(final String branchId) throws GitAPIException { git.merge() .setCommit(true) .include(ObjectId.fromString(branchId)) .call(); }
public Pair<Boolean, String> merge(String branchToUpdate, String branchHead, boolean commit) { Pair<Boolean, String> ret = new Pair<>(false, ""); MergeCommand command = _git.merge(); try { String refName = !branchHead.contains(REFS_HEADS) ? REFS_REMOTES + branchHead : branchHead; command.include(_repo.getRef(refName)); command.setCommit(commit); MergeResult mergeResult = command.call(); ret = checkResult(branchToUpdate, branchHead, ret, mergeResult); } catch (Throwable e) { VerigreenLogger.get().log( getClass().getName(), RuntimeUtils.getCurrentMethodName(), String.format( "Failed to update branch [%s] with parent branch [%s]", branchToUpdate, branchHead)); } return ret; }
protected void doMerge(Exchange exchange, String operation) throws Exception { MergeResult result = null; ObjectId mergeBase; try { if (ObjectHelper.isEmpty(endpoint.getBranchName())) { throw new IllegalArgumentException("Branch name must be specified to execute " + operation); } mergeBase = git.getRepository().resolve(endpoint.getBranchName()); git.checkout().setName("master").call(); result = git.merge().include(mergeBase).setFastForward(FastForwardMode.FF).setCommit(true).call(); } catch (Exception e) { LOG.error("There was an error in Git {} operation", operation); throw e; } updateExchange(exchange, result); }
git.merge() .setStrategy(MergeStrategy.OURS) .include(ref)
private MergeResult merge(Git git, String branch) { try { MergeCommand merge = git.merge(); merge.include(git.getRepository().findRef("origin/" + branch)); MergeResult result = merge.call(); if (!result.getMergeStatus().isSuccessful()) { this.logger.warn("Merged from remote " + branch + " with result " + result.getMergeStatus()); } return result; } catch (Exception ex) { String message = "Could not merge remote for " + branch + " remote: " + git.getRepository().getConfig() .getString("remote", "origin", "url"); warn(message, ex); return null; } }
mRepo.getGit().merge().include(mCommit).setFastForward(ffMode) .call(); } catch (GitAPIException e) {
@Override public void execute() throws GitException, InterruptedException { try (Repository repo = getRepository()) { Git git = git(repo); MergeResult mergeResult; if (strategy != null) mergeResult = git.merge().setMessage(comment).setStrategy(strategy).setFastForward(fastForwardMode).setSquash(squash).setCommit(commit).include(rev).call(); else mergeResult = git.merge().setMessage(comment).setFastForward(fastForwardMode).setSquash(squash).setCommit(commit).include(rev).call(); if (!mergeResult.getMergeStatus().isSuccessful()) { git.reset().setMode(HARD).call(); throw new GitException("Failed to merge " + rev); } } catch (GitAPIException e) { throw new GitException("Failed to merge " + rev, e); } } };
final MergeResult mergeResult = git.merge() .include(commit1.getId()) .setFastForward(FastForwardMode.NO_FF)
MergeResult result = git.merge().include(revCommitBase).setFastForward(MergeCommand.FastForwardMode.NO_FF).call(); this.nbCommits++; } catch (Exception e) {
.call(); MergeResult result = git.merge() .setFastForward(MergeCommand.FastForwardMode.NO_FF) .include(git.getRepository().resolve(patchBranch))
.call(); MergeResult result = git.merge() .setFastForward(MergeCommand.FastForwardMode.NO_FF) .include(git.getRepository().resolve(patchBranch))