Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 315166 - Checkout of remote branch or tag does nothing
Summary: Checkout of remote branch or tag does nothing
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 0.10.0   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 0.12   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-01 02:43 EDT by Mathias Kinzler CLA
Modified: 2011-03-27 16:55 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mathias Kinzler CLA 2010-06-01 02:43:34 EDT
If a local branch is checked out, trying to check out a remote branch or tag that points to the same commit as the local branch appears to do nothing (the branch operation returns with NO_CHANGE). Instead, HEAD should become detached in these cases.
Comment 1 Stefan Lay CLA 2010-08-25 08:24:55 EDT
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?
Comment 2 Stefan Lay CLA 2010-08-27 05:13:37 EDT
Lets do the same as native git does: detach the HEAD.
Comment 3 Mathias Kinzler CLA 2010-10-12 03:11:53 EDT
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?
Comment 4 Sasa Zivkov CLA 2011-03-25 09:56:37 EDT
Proposed a bugfix:
http://egit.eclipse.org/r/#change,2925
Comment 5 Shawn Pearce CLA 2011-03-27 16:55:50 EDT
Commit 3a86868c0883d2a564db88bf9ae4a5fe235bb63f