sodapopcan / vim-twiggy

Git branch management for Vim
282 stars 16 forks source link

Can not checkout remote branch in detached HEAD which name is same with the current local one #12

Closed tracyone closed 6 years ago

tracyone commented 6 years ago
screen shot 2018-03-17 at 09 55 20

I want to git checkout remotes/upstream/master,but it is not work.

I have to checkout branch assets first

sodapopcan commented 6 years ago

I didn't realize that the checkout logic is kind of messed up in general (I suspect it worked better with older versions of git... this part of the code hasn't been updated since the initial release almost 4 years ago).

I have most of a fix ready, but have zero experience working with multiple remotes in collaborative projects. I have a good idea of how I would expect this to work but need a little clarification. To outline, this was my original intended behaviour:

c on a local branch: plain ol' checkout c on a remote branch: checkout a new local tracking branch (or nothing if one already exists) C on a local branch: if it is tracking a remote branch, checkout in detached HEAD C on a remote branch: checkout in detached HEAD

So now I'm realizing c needs a special case: If local master is tracking origin/master and you hit c on upstream/master, it should be checked-out in detached HEAD.

Is that the behaviour you'd expect?

tracyone commented 6 years ago

So now I'm realizing c needs a special case: If local master is tracking origin/master and you hit c on upstream/master, it should be checked-out in detached HEAD.

Do you mean C?

sodapopcan commented 6 years ago

No I meant c—I'm suggesting C and c would do the same thing in this case. c on a remote branch would normally create a local branch and track the remote, but if master is already tracking origin/master and you hit c on on upstream/master then obviously it shouldn't do something like make the local now track upstream/remote, it should just checkout the remote, detached. Yeah?

sodapopcan commented 6 years ago

I've pushed to https://github.com/sodapopcan/vim-twiggy/tree/fix-checkout if you just want to try it out.

tracyone commented 6 years ago

Yes.

I expect: In the screenshot, cureent local branch is master(from origin):

  1. c on r:origin:master will do nothing,
  2. c on r:upstream:master` should be checked-out in detached .
  3. C on r:origin:master or r:upstream:master should be checked-out in detached .
sodapopcan commented 6 years ago

Yes, perfect. I just wanted to clarify and make sure my line of thinking was correct.

If you don't mind playing around with it a bit first that would be much appreciated. If not, that's cool, I just don't want to put this on master just yet as I want to test a little more. It won't be long, though.

Thanks for reporting!

sodapopcan commented 6 years ago

It's in master now. Let me know if you find anything else!