Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 513503

Summary: Can't checkout local branch that has the same name as a tag
Product: [ECD] Orion Reporter: Remy Suen <remy.suen>
Component: NodeAssignee: Remy Suen <remy.suen>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: steve_northover
Version: 13.0   
Target Milestone: 15.0   
Hardware: All   
OS: All   
Whiteboard:

Description Remy Suen CLA 2017-03-10 18:00:00 EST
1. Open the Git page.
2. Create a tag on your top most commit. Choose a name that doesn't conflict with any other local branches.
4. Click the references drop down at the top.
5. Find the tag you just created
6. Click the checkout icon. Reuse the same name as the tag. Click the 'Submit' button.
7. Notice that you are still on your original branch. Try to use the drop down to checkout the local branch. It will not work.

------------------

To workaround the problem:
1. Change HEAD to point at your other local branch via the references drop down.
2. Click the checkout icon on your other branch's top most incoming commit and then enter in a new name that doesn't conflict with a tag. Click the 'Submit' button and you're good to go.
Comment 1 Remy Suen CLA 2017-03-10 18:06:48 EST
This boolean check is failing so nothing is happening.

https://github.com/nodegit/nodegit/blob/v0.16.0/lib/repository.js#L311-L313
Comment 2 Remy Suen CLA 2017-03-10 18:13:03 EST
See bug 347289. It seems that a similar problem happened many moons ago with the Java server.
Comment 3 Remy Suen CLA 2017-03-10 23:50:27 EST
Quite simply, the fix is to prepend the "refs/heads/" string prior to checking out the branch.

https://github.com/eclipse/orion.client/blob/e10609e58dc278f8f7e9d00643c10f5890d7a3da/modules/orionode/lib/git/clone.js#L431

This has the unfortunate side effect of breaking clients that previously sent in a fully qualified name for the checkout. However, given that the Java server also prepends this string, I'm inclined to let this go.

https://github.com/eclipse/orion.server/blob/f3cc7aec9f1b6fb19546bff03eceb49dd125bbd0/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCloneHandlerV1.java#L426

Alternatively, we massage the Orion client to prepend the "refs/heads/" string and remove that string concatenation on the Java server and ask our API consumers to use a fully qualified branch name in the parameter.

https://github.com/eclipse/orion.client/blob/b60bda327af4012a1201cffc8e0810144b776f40/bundles/org.eclipse.orion.client.git/web/orion/git/gitClient.js#L407

However, the Git API has never expected the fully qualified branch name for the parameter and the simple name is what's written on the wiki page so I'm leaning towards making the behaviour of the Node server match the Java server instead of forcing clients to change their API calls to use a fully qualified reference.

https://wiki.eclipse.org/index.php?title=Orion/Server_API/Git_API&diff=258174&oldid=258172#Checking_out_a_branch

One could perhaps argue we could choose to modify both the Java and the Node server to prepend the string if and only if the string isn't already there but I feel that a simple API is better than one with conveniences built-in to help massage the parameters of the API.
Comment 4 Remy Suen CLA 2017-03-11 04:49:45 EST
I have opened a pull request against NodeGit that illustrates the failure.

https://github.com/nodegit/nodegit/pull/1250
Comment 5 Remy Suen CLA 2017-03-11 05:22:48 EST
(In reply to Remy Suen from comment #3)
> https://wiki.eclipse.org/index.php?title=Orion/Server_API/
> Git_API&diff=258174&oldid=258172#Checking_out_a_branch

Sorry, I copied the right link. Here's the right diff to the wiki page.

https://wiki.eclipse.org/index.php?title=Orion/Server_API/Git_API&diff=next&oldid=258174
Comment 6 Remy Suen CLA 2017-04-01 20:04:52 EDT
I've decided to make the Node server match the Java server as that seems to be the best way to provide compatibility.

I have delivered the first pass of the fix to master.

https://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=d4033e43564dd356412bd4171ab23cd21e7233e4

This fixes the latter problem where you can't checkout a branch with the same name as the tag. The first problem encountered in comment 0 is that creating a branch off of an existing tag will fail to automatically checkout the branch.
Comment 7 Remy Suen CLA 2017-04-02 09:59:43 EDT
Trying to checkout a tag (which will cause the server to both create the branch and check it out) with the created branch having the same name as the tag now works too.

https://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=c7ff8130a9b928eed30f322a34cde70cbe7ee688