{"thread":{"id":"46322","subject":"bug during checkout of remote branch and uncommited changes ?","startedAt":"2017-07-07T12:37:37Z","lastAt":"2017-07-07T21:29:25Z","messageCount":5,"participants":["Luc Van Oostenryck","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"323950","messageId":"20170707123727.dgd5rub2ycrg525y@ltop.local","threadId":"46322","inReplyTo":null,"subject":"bug during checkout of remote branch and uncommited changes ?","fromName":"Luc Van Oostenryck","fromEmail":"luc.vanoostenryck@gmail.com","sentAt":"2017-07-07T12:37:28Z","receivedAt":"2017-07-07T12:37:37Z","isPatch":false,"sender":{"key":"luc.vanoostenryck@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16168334?v=4"},"body":"Hi,\n\nLately I've been caught several time with a problem which,\nto me, is a bug. It can easily be reproduced, so I think\nIt's very possible it has already been reported.\n\nThe problem arise when trying to checkout a branch while having\nsome uncommited changes. The scenario is the following:\n\t$ git status\n\tM  afile.c\n\t$ git remote add <aremote> <anurl> \n\t$ git fetch <aremote> <abranch>\n\tremote: Counting objects: 7, done.\n\tremote: Compressing objects: 100% (6/6), done.\n\tremote: Total 7 (delta 5), reused 3 (delta 1)\n\tUnpacking objects: 100% (7/7), done.\n\tFrom <anurl>\n\t * branch                <abranch> -> FETCH_HEAD\n\t * [new branch]          <abranch> -> <aremote>/<abranch>\n\t$ git co <abranch>\n\terror: Your local changes to the following files would be overwritten by checkout:\n\t\tafile.c\n\tPlease commit your changes or stash them before you switch branches.\n\tAborting\n\t$ git reset --hard\n\tpatching file afile.c\n\t$ git co <abranch>\n\tfatal: Not tracking: ambiguous information for ref refs/remotes/<aremote>/<abranch>\n\nWhat can be ambiguous here?\nStrangely, trying a second time, succeed:\n\t$ git co <abranch>\n\tPrevious HEAD position was ...\n\tSwitched to branch '<abranch>'\n\n-- Luc Van Oostenryck\n"},{"id":"323956","messageId":"xmqqd19cckfw.fsf@gitster.mtv.corp.google.com","threadId":"46322","inReplyTo":"20170707123727.dgd5rub2ycrg525y@ltop.local","subject":"Re: bug during checkout of remote branch and uncommited changes ?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-07-07T15:53:39Z","receivedAt":"2017-07-07T15:53:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Luc Van Oostenryck <luc.vanoostenryck@gmail.com> writes:\n\n> \t$ git reset --hard\n> \tpatching file afile.c\n\nIs that a message from something?  It does not sound like something\n\"git reset --hard\" would say.\n\n> \t$ git co <abranch>\n> \tfatal: Not tracking: ambiguous information for ref refs/remotes/<aremote>/<abranch>\n>\n> What can be ambiguous here?\n\nI think the message \"Not tracking\" is given when there is a remote\nother than <aremote> that also has <abranch>.  Between the time you\ngot the message and the time you tried to checkout <abranch>, did\nanything happen to cause the second attempt succeed?\n\n> Strangely, trying a second time, succeed:\n> \t$ git co <abranch>\n> \tPrevious HEAD position was ...\n> \tSwitched to branch '<abranch>'\n>\n> -- Luc Van Oostenryck\n"},{"id":"323966","messageId":"20170707171300.kd5hqcujbvubw73q@ltop.local","threadId":"46322","inReplyTo":"xmqqd19cckfw.fsf@gitster.mtv.corp.google.com","subject":"Re: bug during checkout of remote branch and uncommited changes ?","fromName":"Luc Van Oostenryck","fromEmail":"luc.vanoostenryck@gmail.com","sentAt":"2017-07-07T17:13:01Z","receivedAt":"2017-07-07T17:13:19Z","isPatch":false,"sender":{"key":"luc.vanoostenryck@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16168334?v=4"},"body":"On Fri, Jul 07, 2017 at 08:53:39AM -0700, Junio C Hamano wrote:\n> Luc Van Oostenryck <luc.vanoostenryck@gmail.com> writes:\n> \n> > \t$ git reset --hard\n> > \tpatching file afile.c\n> \n> Is that a message from something?  It does not sound like something\n> \"git reset --hard\" would say.\n\nIndeed, sorry. This is the result of a 'git diff | patch -p1 -R' to\nwhich I'm used since a long time ago. I have no more reason to use\nit but ... habits ... :)\n \nBut doing 'git reset --hard' gives exactly the same result.\n\n> > \t$ git co <abranch>\n> > \tfatal: Not tracking: ambiguous information for ref refs/remotes/<aremote>/<abranch>\n> >\n> > What can be ambiguous here?\n> \n> I think the message \"Not tracking\" is given when there is a remote\n> other than <aremote> that also has <abranch>.\n\nMmmm, no I don't have that.\nAt this point there is (in .git):\n\trefs/remotes/<aremote>/<abranch>\n\trefs/heads/<abranch>\nThe second one didn't existed before the checkout attempt, of course.\n\t\n> Between the time you\n> got the message and the time you tried to checkout <abranch>, did\n> anything happen to cause the second attempt succeed?\n\nNo.\nAt least here, the scenario I gave allow to fully reproduce the problem.\n\nWould you like any other information?\n\n-- Luc\n"},{"id":"323979","messageId":"xmqqshi89c3d.fsf@gitster.mtv.corp.google.com","threadId":"46322","inReplyTo":"20170707171300.kd5hqcujbvubw73q@ltop.local","subject":"Re: bug during checkout of remote branch and uncommited changes ?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-07-07T21:22:14Z","receivedAt":"2017-07-07T21:22:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Luc Van Oostenryck <luc.vanoostenryck@gmail.com> writes:\n\n> At least here, the scenario I gave allow to fully reproduce the problem.\n>\n> Would you like any other information?\n\nNot really.  Here is what I locally ran and its output\n\n-- >8 -- cut here -- >8 --\n\n#!/bin/sh\n\nmkdir -p /var/tmp/x/lvo && cd /var/tmp/x/lvo || exit\n\nrm -fr src dst\n\n(\n\tmkdir src &&\n\tcd src &&\n\tgit init &&\n\t>file &&\n\tgit add file &&\n\tgit commit -m 'initial' &&\n\tgit checkout -b abranch &&\n\techo abranch >file &&\n\tgit commit -a -m 'abranch'\n) || exit\n\nmkdir dst &&\ncd dst &&\ngit init &&\ngit pull ../src master &&\necho mine >file &&\ngit status -suno &&\ngit remote add aremote ../src &&\ngit fetch aremote abranch || exit\n\ngit checkout abranch\n\ngit reset --hard\n\ngit checkout abranch\n\n-- 8< -- cut here -- 8< --\n\n$ sh script\nInitialized empty Git repository in /var/tmp/x/lvo/src/.git/\n[master (root-commit) 8535bd5] initial\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 file\nSwitched to a new branch 'abranch'\n[abranch 32814d9] abranch\n 1 file changed, 1 insertion(+)\nInitialized empty Git repository in /var/tmp/x/lvo/dst/.git/\nFrom ../src\n * branch            master     -> FETCH_HEAD\n M file\nFrom ../src\n * branch            abranch    -> FETCH_HEAD\n * [new branch]      abranch    -> aremote/abranch\nerror: Your local changes to the following files would be overwritten by checkout:\n\tfile\nPlease commit your changes or stash them before you switch branches.\nAborting\nHEAD is now at 8535bd5 initial\nSwitched to a new branch 'abranch'\nBranch abranch set up to track remote branch abranch from aremote.\n\n----------------------------------------\n\nAs far as I can see, everything is working as intended.  The first\n\"git checkout abranch\" stops due to the dirty local state before it\neven tries to DWIM to create abranch, and then after resetting to\nget rid of all the local modifications, the second \"git checkout\nabranch\" manages to create the branch just fine.\n\nEven with different variations (like making dst a clone of src to\nforce the \"checkout\" to see an ambiguity), I do not seem to get your\n\"the first one fails with an error message about Ambiguity, the\nsecond does not\", which indeed is a curious symptom.\n\nWithout knowing if this is an ancient Git, or what remote other than\naremote this repository has, what remote-tracking branches from\nthese remotes this repository has, if they share the same name\nabranch that points at the same or different objects, etc., I simply\ndo not know what is causing you the symptom, and time I allocated to\nlook into this for now just ran out.\n\n\n"},{"id":"323980","messageId":"CAMHZB6Hwc=wiJ=R7fQZ+XB-i9_JP09qV9tm6jZRTUBgJgpvn=Q@mail.gmail.com","threadId":"46322","inReplyTo":"xmqqshi89c3d.fsf@gitster.mtv.corp.google.com","subject":"Re: bug during checkout of remote branch and uncommited changes ?","fromName":"Luc Van Oostenryck","fromEmail":"luc.vanoostenryck@gmail.com","sentAt":"2017-07-07T21:29:17Z","receivedAt":"2017-07-07T21:29:25Z","isPatch":false,"sender":{"key":"luc.vanoostenryck@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16168334?v=4"},"body":"On Fri, Jul 7, 2017 at 11:22 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Luc Van Oostenryck <luc.vanoostenryck@gmail.com> writes:\n>\n>> At least here, the scenario I gave allow to fully reproduce the problem.\n>>\n>> Would you like any other information?\n>\n> Not really.  Here is what I locally ran and its output\n>\n> -- >8 -- cut here -- >8 --\n>\n> #!/bin/sh\n>\n> mkdir -p /var/tmp/x/lvo && cd /var/tmp/x/lvo || exit\n>\n> rm -fr src dst\n>\n> (\n>         mkdir src &&\n>         cd src &&\n>         git init &&\n>         >file &&\n>         git add file &&\n>         git commit -m 'initial' &&\n>         git checkout -b abranch &&\n>         echo abranch >file &&\n>         git commit -a -m 'abranch'\n> ) || exit\n>\n> mkdir dst &&\n> cd dst &&\n> git init &&\n> git pull ../src master &&\n> echo mine >file &&\n> git status -suno &&\n> git remote add aremote ../src &&\n> git fetch aremote abranch || exit\n>\n> git checkout abranch\n>\n> git reset --hard\n>\n> git checkout abranch\n>\n> -- 8< -- cut here -- 8< --\n>\n> $ sh script\n> Initialized empty Git repository in /var/tmp/x/lvo/src/.git/\n> [master (root-commit) 8535bd5] initial\n>  1 file changed, 0 insertions(+), 0 deletions(-)\n>  create mode 100644 file\n> Switched to a new branch 'abranch'\n> [abranch 32814d9] abranch\n>  1 file changed, 1 insertion(+)\n> Initialized empty Git repository in /var/tmp/x/lvo/dst/.git/\n> From ../src\n>  * branch            master     -> FETCH_HEAD\n>  M file\n> From ../src\n>  * branch            abranch    -> FETCH_HEAD\n>  * [new branch]      abranch    -> aremote/abranch\n> error: Your local changes to the following files would be overwritten by checkout:\n>         file\n> Please commit your changes or stash them before you switch branches.\n> Aborting\n> HEAD is now at 8535bd5 initial\n> Switched to a new branch 'abranch'\n> Branch abranch set up to track remote branch abranch from aremote.\n>\n> ----------------------------------------\n>\n> As far as I can see, everything is working as intended.  The first\n> \"git checkout abranch\" stops due to the dirty local state before it\n> even tries to DWIM to create abranch, and then after resetting to\n> get rid of all the local modifications, the second \"git checkout\n> abranch\" manages to create the branch just fine.\n>\n> Even with different variations (like making dst a clone of src to\n> force the \"checkout\" to see an ambiguity), I do not seem to get your\n> \"the first one fails with an error message about Ambiguity, the\n> second does not\", which indeed is a curious symptom.\n>\n> Without knowing if this is an ancient Git, or what remote other than\n> aremote this repository has, what remote-tracking branches from\n> these remotes this repository has, if they share the same name\n> abranch that points at the same or different objects, etc., I simply\n> do not know what is causing you the symptom, and time I allocated to\n> look into this for now just ran out.\n\nStrange.\nI forgot to say that I was using git 2.13.0\n\nI have a few more remote but 'abranch' was just a new branch (with\nname unique to the remote) with fresh objects.\n\nI'll investigate things more here and report if anything new.\nThanks, for your time.\n\n-- Luc\n"}]}