{"thread":{"id":"40719","subject":"[BUG] Wrong worktree path when using multiple worktree","startedAt":"2015-11-03T16:58:06Z","lastAt":"2015-11-04T02:23:52Z","messageCount":3,"participants":["Nicolas Morey-Chaisemartin","Mike Rappazzo"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"272839","messageId":"5638E79E.10407@morey-chaisemartin.com","threadId":"40719","inReplyTo":null,"subject":"[BUG] Wrong worktree path when using multiple worktree","fromName":"Nicolas Morey-Chaisemartin","fromEmail":"nicolas@morey-chaisemartin.com","sentAt":"2015-11-03T16:58:06Z","receivedAt":"2015-11-03T16:58:06Z","isPatch":false,"sender":{"key":"devel-git@morey-chaisemartin.com","avatar":"https://avatars.githubusercontent.com/u/108326?v=4"},"body":"Hi,\n\nThere seem to be an issue with the path computed for a worktree when multiple worktree were created (using git worktree)\nIn my Setup, I have 3 repos:\nA/repo (main One)\nA/repo-patches (worktree, using branch dev)\nB/repo (worktree, using branch next)\n\nI'm working in A/repo-patches an run:\n$ git checkout next\nfatal: 'next' is already checked out at 'A/repo-patches'\n\nWhich is partially true but not completely.\nI looked a bit in the code and found that the issue comes from here (get_linked_worktree):\n    if (!strbuf_strip_suffix(&worktree_path, \"/.git\")) {\n        strbuf_reset(&worktree_path);\n        strbuf_addstr(&worktree_path, absolute_path(\".\"));\n        strbuf_strip_suffix(&worktree_path, \"/.\");\n    }\nBecause it wrongfully assumes that I am in the linked worktree.\nI checked in the .git/worktree files and couldn't see anything that actually points to where the repo are setup.\n\nNicolas\n"},{"id":"272862","messageId":"CANoM8SVOPpOvnykGxfw+dn1Twwe8S=WKfePogx+GRQeAjn6D7g@mail.gmail.com","threadId":"40719","inReplyTo":"5638E79E.10407@morey-chaisemartin.com","subject":"Re: [BUG] Wrong worktree path when using multiple worktree","fromName":"Mike Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2015-11-03T22:27:31Z","receivedAt":"2015-11-03T22:27:31Z","isPatch":false,"sender":{"key":"rappazzo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/525287?v=4"},"body":"On Tue, Nov 3, 2015 at 11:58 AM, Nicolas Morey-Chaisemartin\n<nicolas@morey-chaisemartin.com> wrote:\n> Hi,\n>\n> There seem to be an issue with the path computed for a worktree when multiple worktree were created (using git worktree)\n> In my Setup, I have 3 repos:\n> A/repo (main One)\n> A/repo-patches (worktree, using branch dev)\n> B/repo (worktree, using branch next)\n>\n> I'm working in A/repo-patches an run:\n> $ git checkout next\n> fatal: 'next' is already checked out at 'A/repo-patches'\n>\n> Which is partially true but not completely.\n> I looked a bit in the code and found that the issue comes from here (get_linked_worktree):\n>     if (!strbuf_strip_suffix(&worktree_path, \"/.git\")) {\n>         strbuf_reset(&worktree_path);\n>         strbuf_addstr(&worktree_path, absolute_path(\".\"));\n>         strbuf_strip_suffix(&worktree_path, \"/.\");\n>     }\n> Because it wrongfully assumes that I am in the linked worktree.\n> I checked in the .git/worktree files and couldn't see anything that actually points to where the repo are setup.\n>\n> Nicolas\n\nThis is code that I worked on, but I am unable to reproduce it locally\njust yet.  Before I dig too deep, could you report the contents of\n\"A/repo/.git/worktrees/repo-patches/gitdir\" (or similar)?  There is\nanother issue reported[1] where the contents of the gitdir for a\nlinked worktree are overwritten in some cases.  A fix for this is\nbeing worked on (see discussion).\n\nIn the mean time, I will continue to try and reproduce.\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/280307\n"},{"id":"272877","messageId":"CANoM8SXKmqq5qpv7vFobyAj9mL0wxFPqWeTt5oJT1EP0+=NqwA@mail.gmail.com","threadId":"40719","inReplyTo":"CANoM8SVOPpOvnykGxfw+dn1Twwe8S=WKfePogx+GRQeAjn6D7g@mail.gmail.com","subject":"Re: [BUG] Wrong worktree path when using multiple worktree","fromName":"Mike Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2015-11-04T02:23:52Z","receivedAt":"2015-11-04T02:23:52Z","isPatch":false,"sender":{"key":"rappazzo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/525287?v=4"},"body":"On Tue, Nov 3, 2015 at 5:27 PM, Mike Rappazzo <rappazzo@gmail.com> wrote:\n> On Tue, Nov 3, 2015 at 11:58 AM, Nicolas Morey-Chaisemartin\n> <nicolas@morey-chaisemartin.com> wrote:\n>> Hi,\n>>\n>> There seem to be an issue with the path computed for a worktree when multiple worktree were created (using git worktree)\n>> In my Setup, I have 3 repos:\n>> A/repo (main One)\n>> A/repo-patches (worktree, using branch dev)\n>> B/repo (worktree, using branch next)\n>>\n>> I'm working in A/repo-patches an run:\n>> $ git checkout next\n>> fatal: 'next' is already checked out at 'A/repo-patches'\n>>\n>> Which is partially true but not completely.\n>> I looked a bit in the code and found that the issue comes from here (get_linked_worktree):\n>>     if (!strbuf_strip_suffix(&worktree_path, \"/.git\")) {\n>>         strbuf_reset(&worktree_path);\n>>         strbuf_addstr(&worktree_path, absolute_path(\".\"));\n>>         strbuf_strip_suffix(&worktree_path, \"/.\");\n>>     }\n>> Because it wrongfully assumes that I am in the linked worktree.\n>> I checked in the .git/worktree files and couldn't see anything that actually points to where the repo are setup.\n>>\n>> Nicolas\n>\n> This is code that I worked on, but I am unable to reproduce it locally\n> just yet.  Before I dig too deep, could you report the contents of\n> \"A/repo/.git/worktrees/repo-patches/gitdir\" (or similar)?  There is\n> another issue reported[1] where the contents of the gitdir for a\n> linked worktree are overwritten in some cases.  A fix for this is\n> being worked on (see discussion).\n>\n> In the mean time, I will continue to try and reproduce.\n>\n> [1]: http://thread.gmane.org/gmane.comp.version-control.git/280307\n\nFollowup:  I was able to reproduce the error when I tried to simulate\nthe aforementioned bug.  Here is a test which I added to t2027 (not\nintended to publish):\n\n+test_expect_success '\"checkout\" branch already checked out' '\n+ git worktree add -b linked_1_br linked_1 master &&\n+ git worktree add -b linked_2_br linked_2 master &&\n+ echo \".git\" > .git/worktrees/linked_2/gitdir &&\n+ test_must_fail git -C linked_1 checkout linked_2_br\n+'\n+\n\nTest run result:\n--------------------\nPreparing linked_1 (identifier linked_1)\nHEAD is now at 2519212 init\nPreparing linked_2 (identifier linked_2)\nHEAD is now at 2519212 init\nfatal: 'linked_2_br' is already checked out at\n'/Users/mike/code/git-source/t/trash\ndirectory.t2027-worktree-list/linked_1'\n"}]}