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);
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 {

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 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: ";
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;
}
}

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

@ -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() },

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

@ -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;

Loading…
Cancel
Save