{"thread":{"id":"62722","subject":"How to relocate common and workdir?","startedAt":"2025-01-02T09:46:16Z","lastAt":"2025-01-06T04:18:11Z","messageCount":2,"participants":["Jörg Sommer","Eric Sunshine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"509788","messageId":"h7zchkwkm7djm5qrxnwyh7jvzymrtuzlc4rllnllrcxlrvgtx7@jiu7eiekjit5","threadId":"62722","inReplyTo":null,"subject":"How to relocate common and workdir?","fromName":"Jörg Sommer","fromEmail":"joerg@jo-so.de","sentAt":"2025-01-02T09:30:15Z","receivedAt":"2025-01-02T09:46:16Z","isPatch":false,"sender":{"key":"joerg@jo-so.de","avatar":null},"body":"Hello,\n\nthe KAS project currently discusses a patch [1] to relocate the common dir\nand adjust the .git file in the worktree to match the new location. Is there\nsomething else to adjust than just the .git file?\n\n[1] https://groups.google.com/g/kas-devel/c/OM7bm-tjyLM\n\nThe background is that the git repository gets mounted inside a Docker\ncontainer at a fixed position /repo. This works fine for pure git\nrepositories, but with shared worktrees this fails, because the location in\nthe file /repo/.git is not inside the container.\n\nNow, the idea is to mount $(git rev-parse --common-dir) at /repo-common\ninside the container, and overlay /repo/.git (via bind-mount) with a new\nfile that refers to /repo-common: `sed \"s|gitdir: ${git_com_dir}/|gitdir:\n/repo-common/|\" \"${KAS_REPO_DIR}/.git\"`.\n\nI saw that there are also the files *commondir* and *gitdir* in\n*.git/worktrees/…*. I suspect there are circumstances these files need\nadjustments, too.\n\nIs it really that easy and safe to modify the .git file and point to a new\nlocation of the common-dir, or has to be done more?\n\n\nThanks for your help.\n\nKind regards, Jörg\n\n-- \nMit Statistik kann man alles zeigen – sogar das Gegenteil.\n"},{"id":"509946","messageId":"CAPig+cSVmO5+FtVMyB_0tECkmrEKT8RMnQRZ=y8y6-QsGqer5A@mail.gmail.com","threadId":"62722","inReplyTo":"h7zchkwkm7djm5qrxnwyh7jvzymrtuzlc4rllnllrcxlrvgtx7@jiu7eiekjit5","subject":"Re: How to relocate common and workdir?","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2025-01-06T04:17:59Z","receivedAt":"2025-01-06T04:18:11Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Jan 2, 2025 at 4:46 AM Jörg Sommer <joerg@jo-so.de> wrote:\n> I saw that there are also the files *commondir* and *gitdir* in\n> *.git/worktrees/…*. I suspect there are circumstances these files need\n> adjustments, too.\n>\n> Is it really that easy and safe to modify the .git file and point to a new\n> location of the common-dir, or has to be done more?\n\nAs long as \"${repo}/worktrees/${wtid}/gitdir\" and\n\"${worktreepath}/.git\" are agreement with one another -- that is,\npointing at one another -- everything should be fine. That's all\nthat's needed for healthy linkage between the repository and the\nworktree. You usually don't have to touch\n\"${repo}/worktrees/${wtid}/commondir\" -- unless you have some really\nfunky layout -- since that normally just points up at \"${repo}\".\n\nBy the way, you may be interested in the new \"--relative-paths\" paths\noption of git-worktree and the related configuration\n\"worktree.useRelativePaths\" and \"extension.relativeWorktrees\" which\nwill be part of Git 2.48.0 release, and which was (at least in part)\nmotivated by the sort of use-case you describe.\n"}]}