List of usage examples for org.eclipse.jgit.api CherryPickResult getStatus
public CherryPickStatus getStatus()
From source file:de.blizzy.documentr.page.CherryPicker.java
License:Open Source License
private CommitCherryPickResult cherryPick(ILockedRepository repo, String branchName, String path, PageVersion pageVersion, String targetBranch, Set<CommitCherryPickConflictResolve> conflictResolves, User user, Locale locale) throws IOException, GitAPIException { CommitCherryPickResult cherryPickResult; CherryPickResult result = Git.wrap(repo.r()).cherryPick() .include(repo.r().resolve(pageVersion.getCommitName())).call(); CherryPickStatus status = result.getStatus(); switch (status) { case OK:// w ww. j av a 2 s . c o m cherryPickResult = new CommitCherryPickResult(pageVersion, CommitCherryPickResult.Status.OK); break; case CONFLICTING: cherryPickResult = tryResolveConflict(repo, branchName, path, pageVersion, targetBranch, conflictResolves, user, locale); break; default: cherryPickResult = null; break; } return cherryPickResult; }
From source file:org.eclipse.egit.ui.internal.commit.command.CherryPickHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { RevCommit commit = getSelectedItem(RevCommit.class, event); if (commit == null) return null; Repository repo = getSelectedItem(Repository.class, event); if (repo == null) return null; final Shell parent = getPart(event).getSite().getShell(); if (!confirmCherryPick(parent, repo, commit)) return null; final CherryPickOperation op = new CherryPickOperation(repo, commit); Job job = new Job(MessageFormat.format(UIText.CherryPickHandler_JobName, commit.name())) { @Override/*from w w w .j av a2s. c o m*/ protected IStatus run(IProgressMonitor monitor) { try { op.execute(monitor); CherryPickResult cherryPickResult = op.getResult(); RevCommit newHead = cherryPickResult.getNewHead(); if (newHead != null && cherryPickResult.getCherryPickedRefs().isEmpty()) showNotPerformedDialog(parent); if (newHead == null) { CherryPickStatus status = cherryPickResult.getStatus(); switch (status) { case CONFLICTING: showConflictDialog(parent); break; case FAILED: showFailure(cherryPickResult); break; case OK: break; } } } catch (CoreException e) { Activator.logError(UIText.CherryPickOperation_InternalError, e); } return Status.OK_STATUS; } @Override public boolean belongsTo(Object family) { if (JobFamilies.CHERRY_PICK.equals(family)) return true; return super.belongsTo(family); } }; job.setUser(true); job.setRule(op.getSchedulingRule()); job.schedule(); return null; }
From source file:org.eclipse.orion.server.git.servlets.GitCommitHandlerV1.java
License:Open Source License
private boolean cherryPick(HttpServletRequest request, HttpServletResponse response, Repository db, String commitToCherryPick) throws ServletException, JSONException { try {/*from w ww .jav a2 s .c o m*/ ObjectId objectId = db.resolve(commitToCherryPick); Git git = new Git(db); CherryPickResult cherryPickResult = git.cherryPick().include(objectId).call(); JSONObject result = new JSONObject(); result.put(GitConstants.KEY_RESULT, cherryPickResult.getStatus().name()); OrionServlet.writeJSONResponse(request, response, result); return true; } catch (IOException e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when cherry-picking.", e)); } catch (GitAPIException e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when cherry-picking.", e)); } catch (JGitInternalException e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when cherry-picking.", e.getCause())); } }
From source file:org.jboss.forge.addon.git.GitUtilsTest.java
License:Open Source License
@Test public void shouldNotCrashWhenCherryPickNoMergeIsCalledOnLastCommit() throws Exception { String[] branchNames = { "master" }; String[] files = { "test1.txt" }; List<String> commits = null; CherryPickResult cherryPickResult = null; Project project = projectFactory.createTempProject(); Git repo = gitUtils.init(project.getRoot().reify(DirectoryResource.class)); gitUtils.addAll(repo);//from w w w .ja v a 2s. c o m gitUtils.commitAll(repo, "initial commit"); FileResource<?> file0 = project.getRoot().getChild(files[0]).reify(FileResource.class); file0.createNewFile(); gitUtils.add(repo, files[0]); gitUtils.commit(repo, "file added on " + branchNames[0]); commits = gitUtils.getLogForCurrentBranch(repo); Assert.assertEquals("Wrong number of commits in log", 2, commits.size()); cherryPickResult = gitUtils.cherryPickNoMerge(repo, repo.getRepository().findRef(branchNames[0])); Assert.assertEquals("Wrong cherrypick status", CherryPickResult.CherryPickStatus.OK, cherryPickResult.getStatus()); gitUtils.resetHard(repo, "HEAD^1"); commits = gitUtils.getLogForCurrentBranch(repo); Assert.assertEquals("Wrong number of commits in log", 1, commits.size()); try { gitUtils.cherryPickNoMerge(repo, repo.getRepository().findRef(branchNames[0])); Assert.fail("Expected exception: " + CantMergeCommitException.class); } catch (CantMergeCommitException cmce) { // Expected } }
From source file:org.jboss.forge.git.GitUtilsTest.java
License:Open Source License
@Test(expected = CantMergeCommitWithZeroParentsException.class) public void shouldNotCrashWhenCherryPickNoMergeIsCalledOnLastCommit() throws Exception { String[] branchNames = { "master" }; String[] files = { "test1.txt" }; List<String> commits = null; CherryPickResult cherryPickResult = null; Project project = initializeJavaProject(); Git repo = GitUtils.init(project.getProjectRoot()); GitUtils.addAll(repo);/*from ww w .j a v a 2s . c om*/ GitUtils.commitAll(repo, "initial commit"); FileResource<?> file0 = project.getProjectRoot().getChild(files[0]).reify(FileResource.class); file0.createNewFile(); GitUtils.add(repo, files[0]); GitUtils.commit(repo, "file added on " + branchNames[0]); commits = GitUtils.getLogForCurrentBranch(repo); Assert.assertEquals("Wrong number of commits in log", 2, commits.size()); cherryPickResult = GitUtils.cherryPickNoMerge(repo, repo.getRepository().getRef(branchNames[0])); Assert.assertEquals("Wrong cherrypick status", CherryPickResult.CherryPickStatus.OK, cherryPickResult.getStatus()); GitUtils.resetHard(repo, "HEAD^1"); commits = GitUtils.getLogForCurrentBranch(repo); Assert.assertEquals("Wrong number of commits in log", 1, commits.size()); GitUtils.cherryPickNoMerge(repo, repo.getRepository().getRef(branchNames[0])); }