List of usage examples for org.eclipse.jgit.api MergeCommand setCommit
public MergeCommand setCommit(boolean commit)
From source file:br.com.riselabs.cotonet.builder.NetworkBuilder.java
License:Open Source License
/** * Returns the conflicting files of the given scenario. * /*from w ww. j a v a 2 s . com*/ * @param scenario * @return * @throws CheckoutConflictException * @throws GitAPIException */ private List<File> getConflictingFiles(MergeScenario scenario) throws CheckoutConflictException, GitAPIException { Git git = Git.wrap(getProject().getRepository()); // this is for the cases of restarting after exception in a conflict // scenario analysis try { git.reset().setRef(scenario.getLeft().getName()).setMode(ResetType.HARD).call(); } catch (JGitInternalException e) { Logger.log(log, "[" + project.getName() + "] JGit Reset Command ended with exception." + " Trying external reset command."); ExternalGitCommand egit = new ExternalGitCommand(); try { egit.setType(CommandType.RESET).setDirectory(project.getRepository().getDirectory().getParentFile()) .call(); } catch (BlameException e1) { Logger.logStackTrace(log, e1); return null; } } CheckoutCommand ckoutCmd = git.checkout(); ckoutCmd.setName(scenario.getLeft().getName()); ckoutCmd.setStartPoint(scenario.getLeft()); ckoutCmd.call(); MergeCommand mergeCmd = git.merge(); mergeCmd.setCommit(false); mergeCmd.setStrategy(MergeStrategy.RECURSIVE); mergeCmd.include(scenario.getRight()); Set<String> conflictingPaths; try { // dealing with MissingObjectException MergeResult mResult = mergeCmd.call(); // dealing with Ghosts conflicts conflictingPaths = mResult.getConflicts().keySet(); } catch (NullPointerException | JGitInternalException e) { StringBuilder sb = new StringBuilder(); sb.append("[" + project.getName() + ":" + project.getUrl() + "] " + "Skipping merge scenario due to '" + e.getMessage() + "'\n"); sb.append("--> Exception: " + e.getClass()); sb.append("--> Skipped scenario:\n"); sb.append("::Base:" + scenario.getBase().getName() + "\n"); sb.append("::Left:" + scenario.getLeft().getName() + "\n"); sb.append("::Right:" + scenario.getRight().getName() + "\n"); Logger.log(log, sb.toString()); return null; } List<File> result = new ArrayList<File>(); for (String path : conflictingPaths) { result.add(new File(getProject().getRepository().getDirectory().getParent(), path)); } return result; }
From source file:br.com.riselabs.cotonet.test.helpers.ConflictBasedRepositoryTestCase.java
License:Open Source License
public MergeResult runMerge(MergeScenario scenario) throws RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, CheckoutConflictException, GitAPIException { Git git = Git.wrap(db);/* ww w . j a va2 s.c om*/ CheckoutCommand ckoutCmd = git.checkout(); ckoutCmd.setName(scenario.getLeft().getName()); ckoutCmd.setStartPoint(scenario.getLeft()); ckoutCmd.call(); MergeCommand mergeCmd = git.merge(); mergeCmd.setCommit(false); mergeCmd.include(scenario.getRight()); return mergeCmd.call(); }
From source file:com.verigreen.jgit.JGitOperator.java
License:Apache License
public Pair<Boolean, String> merge(String branchToUpdate, String branchHead, boolean commit) { Pair<Boolean, String> ret = new Pair<>(false, ""); MergeCommand command = _git.merge(); try {/*from w w w . j a va 2s. co m*/ 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; }
From source file:org.codehaus.mojo.versions.BumpMojo.java
License:Apache License
void gitMergeNFF(String c, String m) throws MojoExecutionException { try {//from w w w . j ava 2s.c om MergeCommand ff = git.merge(); ff.setCommit(false); ff.setFastForward(FastForwardMode.NO_FF); ff.include(git.getRepository().getRef(m)); MergeResult f = ff.call(); if (!f.getMergeStatus().isSuccessful()) { throw new MojoExecutionException(f.getMergeStatus().toString()); } git.commit().setAll(true).setMessage(c).call(); } catch (GitAPIException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } }