]> source.dussan.org Git - jgit.git/commitdiff
Fix the reflog prefix for cherry-pick, revert and merge commands 05/4205/2
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 8 Sep 2011 16:05:01 +0000 (18:05 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 21 Sep 2011 21:36:26 +0000 (23:36 +0200)
We should see whether the commit was a regular commit or something
else.

Change-Id: I82d8300cf3c53cb2bdcb6495386aadb803e0c6f7
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java

index c8b7e89f1b00ee3646d3cddf2ea6cd63273380be..d3e81e7bc6b6dac50d0ccac8075fa4860ec04547 100644 (file)
@@ -133,7 +133,6 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> {
                                                .newMerger(repo);
                                merger.setWorkingTreeIterator(new FileTreeIterator(repo));
                                merger.setBase(srcParent.getTree());
-
                                if (merger.merge(headCommit, srcCommit)) {
                                        if (AnyObjectId.equals(headCommit.getTree().getId(), merger
                                                        .getResultTreeId()))
@@ -145,6 +144,9 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> {
                                        dco.checkout();
                                        newHead = new Git(getRepository()).commit()
                                                        .setMessage(srcCommit.getFullMessage())
+                                                       .setReflogComment(
+                                                                       "cherry-pick: "
+                                                                                       + srcCommit.getShortMessage())
                                                        .setAuthor(srcCommit.getAuthorIdent()).call();
                                        cherryPickedRefs.add(src);
                                } else {
index d794c797b466cf111410c55d01779107cbc0274b..fc56f9af1184b4bd15d7dea619d0c450460be997 100644 (file)
@@ -114,6 +114,8 @@ public class CommitCommand extends GitCommand<RevCommit> {
         */
        private List<ObjectId> parents = new LinkedList<ObjectId>();
 
+       private String reflogComment;
+
        /**
         * @param repo
         */
@@ -218,10 +220,14 @@ public class CommitCommand extends GitCommand<RevCommit> {
                                                RevCommit revCommit = revWalk.parseCommit(commitId);
                                                RefUpdate ru = repo.updateRef(Constants.HEAD);
                                                ru.setNewObjectId(commitId);
-                                               String prefix = amend ? "commit (amend): " : "commit: ";
-                                               ru.setRefLogMessage(
-                                                               prefix + revCommit.getShortMessage(), false);
-
+                                               if (reflogComment != null) {
+                                                       ru.setRefLogMessage(reflogComment, false);
+                                               } else {
+                                                       String prefix = amend ? "commit (amend): "
+                                                                       : "commit: ";
+                                                       ru.setRefLogMessage(
+                                                                       prefix + revCommit.getShortMessage(), false);
+                                               }
                                                ru.setExpectedOldObjectId(headId);
                                                Result rc = ru.forceUpdate();
                                                switch (rc) {
@@ -667,4 +673,15 @@ public class CommitCommand extends GitCommand<RevCommit> {
                return this;
        }
 
+       /**
+        * Override the message written to the reflog
+        *
+        * @param reflogComment
+        * @return {@code this}
+        */
+       public CommitCommand setReflogComment(String reflogComment) {
+               this.reflogComment = reflogComment;
+               return this;
+       }
+
 }
index eca7e0b8c06a68c59fefe66d0015e93e720777af..a9f78c076b0084cedad249be7e52431aebbe7f3a 100644 (file)
@@ -217,7 +217,9 @@ public class MergeCommand extends GitCommand<MergeResult> {
                                                        merger.getResultTreeId());
                                        dco.setFailOnConflict(true);
                                        dco.checkout();
-                                       RevCommit newHead = new Git(getRepository()).commit().call();
+
+                                       RevCommit newHead = new Git(getRepository()).commit()
+                                                       .setReflogComment(refLogMessage.toString()).call();
                                        return new MergeResult(newHead.getId(),
                                                        null, new ObjectId[] {
                                                                        headCommit.getId(), srcCommit.getId() },
index 878d9577062f9a4988ab12b3c90dcf5444598b7e..6e27bf287208ab7f41af78db7e7d22df550305a4 100644 (file)
@@ -146,12 +146,13 @@ public class RevertCommand extends GitCommand<RevCommit> {
                                                        merger.getResultTreeId());
                                        dco.setFailOnConflict(true);
                                        dco.checkout();
-                                       String newMessage = "Revert \""
-                                                       + srcCommit.getShortMessage() + "\"" + "\n\n"
+                                       String shortMessage = "Revert \"" + srcCommit.getShortMessage() + "\"";
+                                       String newMessage = shortMessage + "\n\n"
                                                        + "This reverts commit "
                                                        + srcCommit.getId().getName() + ".\n";
-                                       newHead = new Git(getRepository()).commit().setMessage(
-                                                       newMessage).call();
+                                       newHead = new Git(getRepository()).commit()
+                                                       .setMessage(newMessage)
+                                                       .setReflogComment("revert: " + shortMessage).call();
                                        revertedRefs.add(src);
                                } else {
                                        return null;