diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2013-05-06 01:39:25 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2013-08-21 14:44:48 +0200 |
commit | 99d981ce35d66b89cdd5d539513bf0ec070b7b34 (patch) | |
tree | 6d470f04bbf989f0e9a30cb90b8941b6eed33667 /org.eclipse.jgit | |
parent | bd57789735b6f80378db7284470f867e04cbd2b4 (diff) | |
download | jgit-99d981ce35d66b89cdd5d539513bf0ec070b7b34.tar.gz jgit-99d981ce35d66b89cdd5d539513bf0ec070b7b34.zip |
Update reflog like C Git during rebase (non-interactive)
Bug: 346350
Change-Id: I119766a00bc52a810c51cffaa19207cb8555ca22
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java | 22 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java | 31 |
2 files changed, 40 insertions, 13 deletions
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 2ebff14f9c..1b8441170c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java @@ -82,6 +82,8 @@ import org.eclipse.jgit.treewalk.FileTreeIterator; * >Git documentation about cherry-pick</a> */ public class CherryPickCommand extends GitCommand<CherryPickResult> { + private String reflogPrefix = "cherry-pick:"; //$NON-NLS-1$ + private List<Ref> commits = new LinkedList<Ref>(); private String ourCommitName = null; @@ -166,9 +168,8 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> { dco.checkout(); newHead = new Git(getRepository()).commit() .setMessage(srcCommit.getFullMessage()) - .setReflogComment( - "cherry-pick: " //$NON-NLS-1$ - + srcCommit.getShortMessage()) + .setReflogComment(reflogPrefix + " " //$NON-NLS-1$ + + srcCommit.getShortMessage()) .setAuthor(srcCommit.getAuthorIdent()).call(); cherryPickedRefs.add(src); } else { @@ -242,6 +243,21 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> { return this; } + /** + * Set the prefix to use in the reflog. + * <p> + * This is primarily needed for implementing rebase in terms of + * cherry-picking + * + * @param prefix + * including ":" + * @return {@code this} + */ + public CherryPickCommand setReflogPrefix(final String prefix) { + this.reflogPrefix = prefix; + return this; + } + private String calculateOurName(Ref headRef) { if (ourCommitName != null) return ourCommitName; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 911a4e6294..592a012870 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -319,7 +319,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> { String ourCommitName = getOurCommitName(); CherryPickResult cherryPickResult = new Git(repo) .cherryPick().include(commitToPick) - .setOurCommitName(ourCommitName).call(); + .setOurCommitName(ourCommitName) + .setReflogPrefix("rebase:").call(); //$NON-NLS-1$ switch (cherryPickResult.getStatus()) { case FAILED: if (operation == Operation.BEGIN) @@ -353,7 +354,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> { } if (newHead != null) { String headName = rebaseState.readFile(HEAD_NAME); - updateHead(headName, newHead); + updateHead(headName, newHead, upstreamCommit); FileUtils.delete(rebaseState.getDir(), FileUtils.RECURSIVE); if (lastStepWasForward) return RebaseResult.FAST_FORWARD_RESULT; @@ -370,18 +371,20 @@ public class RebaseCommand extends GitCommand<RebaseResult> { private String getOurCommitName() { // If onto is different from upstream, this should say "onto", but // RebaseCommand doesn't support a different "onto" at the moment. - String ourCommitName = "Upstream, based on " + String ourCommitName = "Upstream, based on " //$NON-NLS-1$ + Repository.shortenRefName(upstreamCommitName); return ourCommitName; } - private void updateHead(String headName, RevCommit newHead) + private void updateHead(String headName, RevCommit newHead, RevCommit onto) throws IOException { // point the previous head (if any) to the new commit if (headName.startsWith(Constants.R_REFS)) { RefUpdate rup = repo.updateRef(headName); rup.setNewObjectId(newHead); + rup.setRefLogMessage("rebase finished: " + headName + " onto " //$NON-NLS-1$ + + onto.getName(), false); Result res = rup.forceUpdate(); switch (res) { case FAST_FORWARD: @@ -392,6 +395,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> { throw new JGitInternalException("Updating HEAD failed"); } rup = repo.updateRef(Constants.HEAD); + rup.setRefLogMessage("rebase finished: returning to " + headName, //$NON-NLS-1$ + false); res = rup.link(headName); switch (res) { case FAST_FORWARD: @@ -614,7 +619,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> { if (head.isSymbolic()) headName = head.getTarget().getName(); else - headName = "detached HEAD"; + headName = head.getObjectId().getName(); ObjectId headId = head.getObjectId(); if (headId == null) throw new RefNotFoundException(MessageFormat.format( @@ -629,10 +634,10 @@ public class RebaseCommand extends GitCommand<RebaseResult> { monitor.beginTask(MessageFormat.format( JGitText.get().resettingHead, upstreamCommit.getShortMessage()), ProgressMonitor.UNKNOWN); - checkoutCommit(upstreamCommit); + checkoutCommit(headName, upstreamCommit); monitor.endTask(); - updateHead(headName, upstreamCommit); + updateHead(headName, upstreamCommit, upstream); return RebaseResult.FAST_FORWARD_RESULT; } @@ -691,7 +696,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> { upstreamCommit.getShortMessage()), ProgressMonitor.UNKNOWN); boolean checkoutOk = false; try { - checkoutOk = checkoutCommit(upstreamCommit); + checkoutOk = checkoutCommit(headName, upstreamCommit); } finally { if (!checkoutOk) FileUtils.delete(rebaseState.getDir(), FileUtils.RECURSIVE); @@ -732,7 +737,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> { if (head.isSymbolic()) headName = head.getTarget().getName(); else - headName = "detached HEAD"; + headName = head.getObjectId().getName(); return tryFastForward(headName, headCommit, newCommit); } @@ -843,6 +848,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> { // update the HEAD RefUpdate refUpdate = repo.updateRef(Constants.HEAD, false); + refUpdate.setRefLogMessage("rebase: aborting", false); //$NON-NLS-1$ Result res = refUpdate.link(headName); switch (res) { case FAST_FORWARD: @@ -864,7 +870,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> { } } - private boolean checkoutCommit(RevCommit commit) throws IOException, + private boolean checkoutCommit(String headName, RevCommit commit) + throws IOException, CheckoutConflictException { try { RevCommit head = walk.parseCommit(repo.resolve(Constants.HEAD)); @@ -880,6 +887,10 @@ public class RebaseCommand extends GitCommand<RebaseResult> { RefUpdate refUpdate = repo.updateRef(Constants.HEAD, true); refUpdate.setExpectedOldObjectId(head); refUpdate.setNewObjectId(commit); + refUpdate.setRefLogMessage( + "checkout: moving from " //$NON-NLS-1$ + + Repository.shortenRefName(headName) + + " to " + commit.getName(), false); //$NON-NLS-1$ Result res = refUpdate.forceUpdate(); switch (res) { case FAST_FORWARD: |