{"thread":{"id":"46447","subject":"Bug^Feature? fetch protects only current working tree branch","startedAt":"2017-07-23T14:59:32Z","lastAt":"2017-07-24T21:51:33Z","messageCount":3,"participants":["Andreas Heiduk","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"324915","messageId":"cb957174-5e9a-5603-ea9e-ac9b58a2eaad@mathema.de","threadId":"46447","inReplyTo":null,"subject":"Bug^Feature? fetch protects only current working tree branch","fromName":"Andreas Heiduk","fromEmail":"andreas.heiduk@mathema.de","sentAt":"2017-07-23T14:50:54Z","receivedAt":"2017-07-23T14:59:32Z","isPatch":false,"sender":{"key":"andreas.heiduk@mathema.de","avatar":null},"body":"A `git fetch . origin/master:master` protects the currently checked out \nbranch (HEAD) unless the `-u/--update-head-ok` is supplied. This avoids a\nmismatch between the index and HEAD. BUT branches which are HEADs in other\nworking trees do not get that care - their state is silently screwed up.\n\nIs this intended behaviour or and just an oversight while implementing\n`git worktree`?\n\n\nSteps to reproduce\n\n    # setup\n\n    git clone -b master $SOMETHING xtemp\n    cd xtemp\n    git reset --hard HEAD~5 # pretend to be back some time\n    git worktree add ../xtemp-wt1\n    git worktree add ../xtemp-wt2\n\n    # test\n\n    git fetch . origin/master:master\n    \n        fatal: Refusing to fetch into current branch refs/heads/master  of non-bare repository\n        fatal: The remote end hung up unexpectedly\n\n    # OK, current working tree is protected, try another one:\n\n    git fetch . origin/master:xtemp-wt1\n\n        From .\n           b4d1278..6e7b60d  origin/master -> xtemp-wt1\n\n    cd ../xtemp-wt1\n    git status\n\n        # admire messed up working tree here\n\n    # The protection is really \"current working tree\", not \"first/main working tree\"!\n\n    git fetch . origin/master:master\n\n        From .\n           b4d1278..6e7b60d  origin/master -> master\n\n    cd ../xtemp\n    git status\n\n        # now it's messed up here too\n\n    # Try with \"--update-head-ok\" but check first.\n\n    cd ../xtemp-wt2\n\n    git fetch . origin/master:xtemp-wt2\n\n        fatal: Refusing to fetch into current branch refs/heads/xtemp-wt2 of non-bare repository\n        fatal: The remote end hung up unexpectedly\n\n    git fetch --update-head-ok . origin/master:xtemp-wt2\n        \n        From .\n           b4d1278..6e7b60d  origin/master -> xtemp-wt2\n\n\n"},{"id":"324923","messageId":"xmqqo9saer9f.fsf@gitster.mtv.corp.google.com","threadId":"46447","inReplyTo":"cb957174-5e9a-5603-ea9e-ac9b58a2eaad@mathema.de","subject":"Re: Bug^Feature? fetch protects only current working tree branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-07-23T22:13:16Z","receivedAt":"2017-07-23T22:13:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Heiduk <andreas.heiduk@mathema.de> writes:\n\n> A `git fetch . origin/master:master` protects the currently checked out \n> branch (HEAD) unless the `-u/--update-head-ok` is supplied. This avoids a\n> mismatch between the index and HEAD. BUT branches which are HEADs in other\n> working trees do not get that care - their state is silently screwed up.\n>\n> Is this intended behaviour or and just an oversight while implementing\n> `git worktree`?\n\nThe latter.  \"git worktree\" is an interesting feature and has\npotential to become useful in wider variety of workflows than it\ncurrently is, but end users should consider it still experimental as\nit still is with many such small rough edges like this one.\n\nPatches to help improving the feature is of course very welcome.\n"},{"id":"325008","messageId":"3989d621-e0fd-5075-b42a-abe4fff7ff97@mathema.de","threadId":"46447","inReplyTo":"xmqqo9saer9f.fsf@gitster.mtv.corp.google.com","subject":"Re: Bug^Feature? fetch protects only current working tree branch","fromName":"Andreas Heiduk","fromEmail":"andreas.heiduk@mathema.de","sentAt":"2017-07-24T21:51:17Z","receivedAt":"2017-07-24T21:51:33Z","isPatch":false,"sender":{"key":"andreas.heiduk@mathema.de","avatar":null},"body":"Am 24.07.2017 um 00:13 schrieb Junio C Hamano:\n> Andreas Heiduk <andreas.heiduk@mathema.de> writes:\n> \n>> A `git fetch . origin/master:master` protects the currently checked out \n>> branch (HEAD) unless the `-u/--update-head-ok` is supplied. This avoids a\n>> mismatch between the index and HEAD. BUT branches which are HEADs in other\n>> working trees do not get that care - their state is silently screwed up.\n>>\n>> Is this intended behaviour or and just an oversight while implementing\n>> `git worktree`?\n> \n> The latter.  \n\nOk, so I can adjust some of my helper scripts to catch and forbid this case.\n\n> [...]\"git worktree\" is an interesting feature and has\n> potential to become useful in wider variety of workflows than it\n> currently is, but end users should consider it still experimental as\n> it still is with many such small rough edges like this one.\n> \n> Patches to help improving the feature is of course very welcome.\n\nSince the core of the check is in C, I'll pass on this one. I could\nsupply a patch adding this to the \"BUGS\" section of git-worktree(1)\nthough :-)\n\n\n"}]}