.newMerger(repo);
merger.setWorkingTreeIterator(new FileTreeIterator(repo));
merger.setBase(srcParent.getTree());
-
if (merger.merge(headCommit, srcCommit)) {
if (AnyObjectId.equals(headCommit.getTree().getId(), merger
.getResultTreeId()))
dco.checkout();
newHead = new Git(getRepository()).commit()
.setMessage(srcCommit.getFullMessage())
+ .setReflogComment(
+ "cherry-pick: "
+ + srcCommit.getShortMessage())
.setAuthor(srcCommit.getAuthorIdent()).call();
cherryPickedRefs.add(src);
} else {
*/
private List<ObjectId> parents = new LinkedList<ObjectId>();
+ private String reflogComment;
+
/**
* @param repo
*/
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) {
return this;
}
+ /**
+ * Override the message written to the reflog
+ *
+ * @param reflogComment
+ * @return {@code this}
+ */
+ public CommitCommand setReflogComment(String reflogComment) {
+ this.reflogComment = reflogComment;
+ return this;
+ }
+
}
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() },
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;