{"thread":{"id":"53710","subject":"git init --separate-git-dir doesn't play nice with linked working trees","startedAt":"2020-06-18T16:48:26Z","lastAt":"2020-08-27T08:26:18Z","messageCount":3,"participants":["Henré Botha","Eric Sunshine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"400066","messageId":"CAHbriek39i9NSHRw6DZm0dftk-GkeAYR74c0xyss0vbeDHu1Hw@mail.gmail.com","threadId":"53710","inReplyTo":null,"subject":"git init --separate-git-dir doesn't play nice with linked working trees","fromName":"Henré Botha","fromEmail":"henrebotha@gmail.com","sentAt":"2020-06-18T16:48:08Z","receivedAt":"2020-06-18T16:48:26Z","isPatch":false,"sender":{"key":"henrebotha@gmail.com","avatar":null},"body":"I have identified two potential problems when using git init\n--separate-git-dir with a repo that has linked working trees (created\nusing git worktree add).\n1. Moving the gitdir of a main working tree doesn't inform linked\nworking trees that their gitdir has moved. It seems to me that if I do\ncd main-worktree && git init --separate-git-dir=.git_repo, the git\ninit command should go to all the linked working trees and change\ntheir Git links to point at main-worktree/.git_repo. But perhaps\nthere's some use case I'm not aware of where you'd want to change only\nthe gitdir path of the main working tree, and not those of linked\nworking trees.\n2. Attempting to move the gitdir of a linked working tree breaks the\nlinked working tree entirely.\nIt seems to me that if I do cd linked-worktree && git init\n--separate-git-dir=.git_repo, it should fail, or warn, or do something\nother than break the linked working tree. (I note that\nlinked-worktree/{.git,.git_repo/commondir,.git_repo/gitdir} all point\nat the wrong thing after this operation; manually fixing them restores\nfunctionality, though it loses the link to the main working tree.)\n"},{"id":"400570","messageId":"CAPig+cSaJXqx8F_OXL5uLsQ0g2Y5LQF4Q3b_gFZ+VjSqiN+zfQ@mail.gmail.com","threadId":"53710","inReplyTo":"CAHbriek39i9NSHRw6DZm0dftk-GkeAYR74c0xyss0vbeDHu1Hw@mail.gmail.com","subject":"Re: git init --separate-git-dir doesn't play nice with linked working trees","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-06-25T06:16:12Z","receivedAt":"2020-06-25T06:16:28Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Jun 18, 2020 at 12:48 PM Henré Botha <henrebotha@gmail.com> wrote:\n> I have identified two potential problems when using git init\n> --separate-git-dir with a repo that has linked working trees (created\n> using git worktree add).\n>\n> 1. Moving the gitdir of a main working tree doesn't inform linked\n> working trees that their gitdir has moved. It seems to me that if I do\n> cd main-worktree && git init --separate-git-dir=.git_repo, the git\n> init command should go to all the linked working trees and change\n> their Git links to point at main-worktree/.git_repo. But perhaps\n> there's some use case I'm not aware of where you'd want to change only\n> the gitdir path of the main working tree, and not those of linked\n> working trees.\n\nThis is almost certainly an oversight in the implementation; the\n--separate-git-dir option wasn't mentioned during development of\ngit-worktree as far as I recall.\n\nAs this relocation of the repository is entirely under Git's control\n(as opposed to the user mucking around as with \"mv .git ../foo), it\ndoes indeed seem reasonable that --separate-git-dir should update the\nworktree meta-information files. As far as I know, there is no\nexisting machinery to perform this sort of update, though, so it would\nhave to be implemented from scratch.\n\n> 2. Attempting to move the gitdir of a linked working tree breaks the\n> linked working tree entirely.\n> It seems to me that if I do cd linked-worktree && git init\n> --separate-git-dir=.git_repo, it should fail, or warn, or do something\n> other than break the linked working tree. (I note that\n> linked-worktree/{.git,.git_repo/commondir,.git_repo/gitdir} all point\n> at the wrong thing after this operation; manually fixing them restores\n> functionality, though it loses the link to the main working tree.)\n\nAgain, an oversight; --separate-git-dir wasn't on anyone's mind during\ndevelopment. This is just utterly broken, as far as I can tell; it\ndoesn't move the repository out of the main worktree to the new\nlocation but instead seems to make a copy of it (minus the\n.git/worktrees directory) and drops entries from the original\n.git/worktrees directory, thus breaking everything. I suppose it could\nerror out, though friendlier would be for it to behave correctly.\n"},{"id":"404594","messageId":"CAPig+cQgay71ecYpg9P2FWHsXfQJH_23s9DzqXu+TozcKDw1qA@mail.gmail.com","threadId":"53710","inReplyTo":"CAHbriek39i9NSHRw6DZm0dftk-GkeAYR74c0xyss0vbeDHu1Hw@mail.gmail.com","subject":"Re: git init --separate-git-dir doesn't play nice with linked working trees","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-08-27T08:26:04Z","receivedAt":"2020-08-27T08:26:18Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Jun 18, 2020 at 12:48 PM Henré Botha <henrebotha@gmail.com> wrote:\n> I have identified two potential problems when using git init\n> --separate-git-dir with a repo that has linked working trees (created\n> using git worktree add).\n\nA patch series fixing these problems has been posted[1].\n\n[1]: https://lore.kernel.org/git/20200827082129.56149-1-sunshine@sunshineco.com/T/\n"}]}