From 2058f9272b33753c695fb57bf9126371d3ab7cec Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Mon, 10 Jan 2011 08:47:14 +0100 Subject: [PATCH] Do not cherry-pick or revert commit more than once Instead just return success. In the case that no commit has been cherry-picked or reverted, just return the old HEAD. Bug: 333814 Change-Id: I67db2b77b52c43932436d22a8daa5a6556423484 Signed-off-by: Robin Rosenberg --- .../src/org/eclipse/jgit/api/CherryPickCommand.java | 5 +++++ org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java index 2a57b11ac..153c10000 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java @@ -114,6 +114,8 @@ public class CherryPickCommand extends GitCommand { JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId()); + newHead = headCommit; + // loop through all refs to be cherry-picked for (Ref src : commits) { // get the commit to be cherry-picked @@ -137,6 +139,9 @@ public class CherryPickCommand extends GitCommand { merger.setBase(srcParent.getTree()); if (merger.merge(headCommit, srcCommit)) { + if (AnyObjectId.equals(headCommit.getTree().getId(), merger + .getResultTreeId())) + continue; DirCacheCheckout dco = new DirCacheCheckout(repo, headCommit.getTree(), repo.lockDirCache(), merger.getResultTreeId()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java index 26403edfd..57c69cc08 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java @@ -113,6 +113,8 @@ public class RevertCommand extends GitCommand { JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId()); + newHead = headCommit; + // loop through all refs to be reverted for (Ref src : commits) { // get the commit to be reverted @@ -136,6 +138,9 @@ public class RevertCommand extends GitCommand { merger.setBase(srcCommit.getTree()); if (merger.merge(headCommit, srcParent)) { + if (AnyObjectId.equals(headCommit.getTree().getId(), merger + .getResultTreeId())) + continue; DirCacheCheckout dco = new DirCacheCheckout(repo, headCommit.getTree(), repo.lockDirCache(), merger.getResultTreeId());