From: Robin Rosenberg Date: Thu, 8 Sep 2011 16:05:01 +0000 (+0200) Subject: Fix the reflog prefix for cherry-pick, revert and merge commands X-Git-Tag: v1.2.0.201112221803-r~86 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F05%2F4205%2F2;p=jgit.git Fix the reflog prefix for cherry-pick, revert and merge commands We should see whether the commit was a regular commit or something else. Change-Id: I82d8300cf3c53cb2bdcb6495386aadb803e0c6f7 Signed-off-by: Robin Rosenberg Signed-off-by: Matthias Sohn --- 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 c8b7e89f1b..d3e81e7bc6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java @@ -133,7 +133,6 @@ public class CherryPickCommand extends GitCommand { .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 { dco.checkout(); newHead = new Git(getRepository()).commit() .setMessage(srcCommit.getFullMessage()) + .setReflogComment( + "cherry-pick: " + + srcCommit.getShortMessage()) .setAuthor(srcCommit.getAuthorIdent()).call(); cherryPickedRefs.add(src); } else { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java index d794c797b4..fc56f9af11 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java @@ -114,6 +114,8 @@ public class CommitCommand extends GitCommand { */ private List parents = new LinkedList(); + private String reflogComment; + /** * @param repo */ @@ -218,10 +220,14 @@ public class CommitCommand extends GitCommand { 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 { return this; } + /** + * Override the message written to the reflog + * + * @param reflogComment + * @return {@code this} + */ + public CommitCommand setReflogComment(String reflogComment) { + this.reflogComment = reflogComment; + return this; + } + } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java index eca7e0b8c0..a9f78c076b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java @@ -217,7 +217,9 @@ public class MergeCommand extends GitCommand { 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() }, 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 878d957706..6e27bf2872 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java @@ -146,12 +146,13 @@ public class RevertCommand extends GitCommand { 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;