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>
This commit is contained in:
parent
eadc26c0a0
commit
b695f66487
|
@ -143,8 +143,8 @@ public Ref call() throws JGitInternalException, RefAlreadyExistsException,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref headRef = repo.getRef(Constants.HEAD);
|
Ref headRef = repo.getRef(Constants.HEAD);
|
||||||
String refLogMessage = "checkout: moving from "
|
String shortHeadRef = getShortBranchName(headRef);
|
||||||
+ headRef.getTarget().getName();
|
String refLogMessage = "checkout: moving from " + shortHeadRef;
|
||||||
ObjectId branch = repo.resolve(name);
|
ObjectId branch = repo.resolve(name);
|
||||||
if (branch == null)
|
if (branch == null)
|
||||||
throw new RefNotFoundException(MessageFormat.format(JGitText
|
throw new RefNotFoundException(MessageFormat.format(JGitText
|
||||||
|
@ -169,10 +169,10 @@ public Ref call() throws JGitInternalException, RefAlreadyExistsException,
|
||||||
Ref ref = repo.getRef(name);
|
Ref ref = repo.getRef(name);
|
||||||
if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
|
if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
|
||||||
ref = null;
|
ref = null;
|
||||||
|
String toName = Repository.shortenRefName(name);
|
||||||
RefUpdate refUpdate = repo.updateRef(Constants.HEAD, ref == null);
|
RefUpdate refUpdate = repo.updateRef(Constants.HEAD, ref == null);
|
||||||
refUpdate.setForceUpdate(force);
|
refUpdate.setForceUpdate(force);
|
||||||
refUpdate.setRefLogMessage(refLogMessage + " to "
|
refUpdate.setRefLogMessage(refLogMessage + " to " + toName, false);
|
||||||
+ newCommit.getName(), false);
|
|
||||||
Result updateResult;
|
Result updateResult;
|
||||||
if (ref != null)
|
if (ref != null)
|
||||||
updateResult = refUpdate.link(ref.getName());
|
updateResult = refUpdate.link(ref.getName());
|
||||||
|
@ -216,6 +216,12 @@ public Ref call() throws JGitInternalException, RefAlreadyExistsException,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
* @param path
|
||||||
* Path to update in the working tree and index.
|
* Path to update in the working tree and index.
|
||||||
|
|
Loading…
Reference in New Issue