Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg2011-09-04 09:12:49 +0000
committerMatthias Sohn2011-09-05 15:02:16 +0000
commitb695f66487dfdc5cfe3e3dd22c0253801ecdc9b9 (patch)
tree113b3e139cabb88ec8dae1b9a99ad3c34f48c813
parenteadc26c0a057456cdcb4234bc89846b2207e40f0 (diff)
downloadjgit-b695f66487dfdc5cfe3e3dd22c0253801ecdc9b9.tar.gz
jgit-b695f66487dfdc5cfe3e3dd22c0253801ecdc9b9.tar.xz
jgit-b695f66487dfdc5cfe3e3dd22c0253801ecdc9b9.zip
Fix the names in the reflog for checkouts
We were diverging from the reference implementation. Always use the ref we checkout to as the to-branch the reflog and avoid the refs/heads both in the from-name and to-name. Change-Id: Id973d9102593872e4df41d0788f0eb7c7fd130c4 Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
index 8caff06292..dd9f0c4567 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
@@ -143,8 +143,8 @@ public class CheckoutCommand extends GitCommand<Ref> {
}
Ref headRef = repo.getRef(Constants.HEAD);
- String refLogMessage = "checkout: moving from "
- + headRef.getTarget().getName();
+ String shortHeadRef = getShortBranchName(headRef);
+ String refLogMessage = "checkout: moving from " + shortHeadRef;
ObjectId branch = repo.resolve(name);
if (branch == null)
throw new RefNotFoundException(MessageFormat.format(JGitText
@@ -169,10 +169,10 @@ public class CheckoutCommand extends GitCommand<Ref> {
Ref ref = repo.getRef(name);
if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
ref = null;
+ String toName = Repository.shortenRefName(name);
RefUpdate refUpdate = repo.updateRef(Constants.HEAD, ref == null);
refUpdate.setForceUpdate(force);
- refUpdate.setRefLogMessage(refLogMessage + " to "
- + newCommit.getName(), false);
+ refUpdate.setRefLogMessage(refLogMessage + " to " + toName, false);
Result updateResult;
if (ref != null)
updateResult = refUpdate.link(ref.getName());
@@ -216,6 +216,12 @@ public class CheckoutCommand extends GitCommand<Ref> {
}
}
+ private String getShortBranchName(Ref headRef) {
+ if (headRef.getTarget().getName().equals(headRef.getName()))
+ return headRef.getTarget().getObjectId().getName();
+ return Repository.shortenRefName(headRef.getTarget().getName());
+ }
+
/**
* @param path
* Path to update in the working tree and index.

Back to the top