| Summary: | Checkout of remote branch or tag does nothing | ||
|---|---|---|---|
| Product: | [Technology] JGit | Reporter: | Mathias Kinzler <mathias.kinzler> |
| Component: | JGit | Assignee: | Project Inbox <jgit.core-inbox> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | christian.halstrick, robin, sasa.zivkov, sop, stefan.lay |
| Version: | 0.10.0 | ||
| Target Milestone: | 0.12 | ||
| Hardware: | PC | ||
| OS: | Windows Vista | ||
| Whiteboard: | |||
|
Description
Mathias Kinzler
What is the use case for checking out a remote branch or tag that points to the same commit as the local branch? I would think that a user wants to get the content of the remote branch or the tag. This works now. Do you think that the user expects that the HEAD is detached in this case?One reason for this could be that he then cannot commit a change by mistake. Are there other reasons? Lets do the same as native git does: detach the HEAD. At the moment, JGit does not allow to detach HEAD without changing the ObjectId at the same time. The coding that tries to do this in method BranchOperation.updateHeadRef() looks like this:
...
RefUpdate u = repository.updateRef(Constants.HEAD, detach);
Result res;
if (detach) {
u.setNewObjectId(newCommit.getId());
u.setRefLogMessage(...);
res = u.forceUpdate();
} else {
u.setRefLogMessage(...);
res = u.link(refName);
}
...
"detach" is true if we are switching from a local branch to a remote branch, a tag, or a commit.
Now, all is fine as long as the new object id is different from the old object id. This can occur when trying to checkout a tag or remote branch which happens to point to the same id as the currently checked out local branch. In this case, the update returns with Result.NO_CHANGE and HEAD is not detached.
Perhaps we need something like RefUpdate.unlink() or allow to use null as parameter in the RefUpdate.link() method?
Proposed a bugfix: http://egit.eclipse.org/r/#change,2925 Commit 3a86868c0883d2a564db88bf9ae4a5fe235bb63f |