Browse Source

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 <robin.rosenberg@dewire.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-1.2
Robin Rosenberg 13 years ago committed by Matthias Sohn
parent
commit
4f4e468f6f
  1. 4
      org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java
  2. 21
      org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
  3. 4
      org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
  4. 9
      org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java

4
org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java

@ -133,7 +133,6 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> {
.newMerger(repo); .newMerger(repo);
merger.setWorkingTreeIterator(new FileTreeIterator(repo)); merger.setWorkingTreeIterator(new FileTreeIterator(repo));
merger.setBase(srcParent.getTree()); merger.setBase(srcParent.getTree());
if (merger.merge(headCommit, srcCommit)) { if (merger.merge(headCommit, srcCommit)) {
if (AnyObjectId.equals(headCommit.getTree().getId(), merger if (AnyObjectId.equals(headCommit.getTree().getId(), merger
.getResultTreeId())) .getResultTreeId()))
@ -145,6 +144,9 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> {
dco.checkout(); dco.checkout();
newHead = new Git(getRepository()).commit() newHead = new Git(getRepository()).commit()
.setMessage(srcCommit.getFullMessage()) .setMessage(srcCommit.getFullMessage())
.setReflogComment(
"cherry-pick: "
+ srcCommit.getShortMessage())
.setAuthor(srcCommit.getAuthorIdent()).call(); .setAuthor(srcCommit.getAuthorIdent()).call();
cherryPickedRefs.add(src); cherryPickedRefs.add(src);
} else { } else {

21
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

@ -114,6 +114,8 @@ public class CommitCommand extends GitCommand<RevCommit> {
*/ */
private List<ObjectId> parents = new LinkedList<ObjectId>(); private List<ObjectId> parents = new LinkedList<ObjectId>();
private String reflogComment;
/** /**
* @param repo * @param repo
*/ */
@ -218,10 +220,14 @@ public class CommitCommand extends GitCommand<RevCommit> {
RevCommit revCommit = revWalk.parseCommit(commitId); RevCommit revCommit = revWalk.parseCommit(commitId);
RefUpdate ru = repo.updateRef(Constants.HEAD); RefUpdate ru = repo.updateRef(Constants.HEAD);
ru.setNewObjectId(commitId); ru.setNewObjectId(commitId);
String prefix = amend ? "commit (amend): " : "commit: "; if (reflogComment != null) {
ru.setRefLogMessage(reflogComment, false);
} else {
String prefix = amend ? "commit (amend): "
: "commit: ";
ru.setRefLogMessage( ru.setRefLogMessage(
prefix + revCommit.getShortMessage(), false); prefix + revCommit.getShortMessage(), false);
}
ru.setExpectedOldObjectId(headId); ru.setExpectedOldObjectId(headId);
Result rc = ru.forceUpdate(); Result rc = ru.forceUpdate();
switch (rc) { switch (rc) {
@ -667,4 +673,15 @@ public class CommitCommand extends GitCommand<RevCommit> {
return this; return this;
} }
/**
* Override the message written to the reflog
*
* @param reflogComment
* @return {@code this}
*/
public CommitCommand setReflogComment(String reflogComment) {
this.reflogComment = reflogComment;
return this;
}
} }

4
org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java

@ -217,7 +217,9 @@ public class MergeCommand extends GitCommand<MergeResult> {
merger.getResultTreeId()); merger.getResultTreeId());
dco.setFailOnConflict(true); dco.setFailOnConflict(true);
dco.checkout(); dco.checkout();
RevCommit newHead = new Git(getRepository()).commit().call();
RevCommit newHead = new Git(getRepository()).commit()
.setReflogComment(refLogMessage.toString()).call();
return new MergeResult(newHead.getId(), return new MergeResult(newHead.getId(),
null, new ObjectId[] { null, new ObjectId[] {
headCommit.getId(), srcCommit.getId() }, headCommit.getId(), srcCommit.getId() },

9
org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java

@ -146,12 +146,13 @@ public class RevertCommand extends GitCommand<RevCommit> {
merger.getResultTreeId()); merger.getResultTreeId());
dco.setFailOnConflict(true); dco.setFailOnConflict(true);
dco.checkout(); dco.checkout();
String newMessage = "Revert \"" String shortMessage = "Revert \"" + srcCommit.getShortMessage() + "\"";
+ srcCommit.getShortMessage() + "\"" + "\n\n" String newMessage = shortMessage + "\n\n"
+ "This reverts commit " + "This reverts commit "
+ srcCommit.getId().getName() + ".\n"; + srcCommit.getId().getName() + ".\n";
newHead = new Git(getRepository()).commit().setMessage( newHead = new Git(getRepository()).commit()
newMessage).call(); .setMessage(newMessage)
.setReflogComment("revert: " + shortMessage).call();
revertedRefs.add(src); revertedRefs.add(src);
} else { } else {
return null; return null;

Loading…
Cancel
Save