{"thread":{"id":"60778","subject":"Strange and broken behaviour when GIT_WORK_TREE is direct ancestor of GIT_DIR","startedAt":"2024-01-21T07:33:55Z","lastAt":"2024-01-21T07:33:55Z","messageCount":1,"participants":["LunarLambda"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"487170","messageId":"CAHadoA-Sps2iiL8T15fcRiL0vCUBb9sNxj5=5yrkuiex65AZHA@mail.gmail.com","threadId":"60778","inReplyTo":null,"subject":"Strange and broken behaviour when GIT_WORK_TREE is direct ancestor of GIT_DIR","fromName":"LunarLambda","fromEmail":"lunarlambda@gmail.com","sentAt":"2024-01-21T07:33:42Z","receivedAt":"2024-01-21T07:33:55Z","isPatch":false,"sender":{"key":"lunarlambda@gmail.com","avatar":null},"body":"Hello all,\n\nI have run into very odd behaviour with git's --work-tree option/the\nGIT_WORK_TREE environment variable.\nI was experimenting with a workflow that involves targeted checkouts\nof subdirectories in a repository,\ncommands of the form `git --work-tree=<dir> checkout @:<subdir> -- .`.\nThis worked fine, until I tried passing the parent directory\nor any directory directly up the hierarchy (../, ../../, etc.) to\n--work-tree, either as a relative or absolute path.\nAlmost all git commands behaved strangely or ceased to work at all.\nI could not find any information in the git documentation or online\nabout this being a restriction in git, and given the\nobserved behaviour I believe it to be a bug, though I'm not sure if\nit's something that should work or is something git should reject.\n\n`git ls-tree` works as usual.\n`git --work-tree=../empty-dir ls-tree` also works.\n`git --work-tree=../nonexistent` also works.\n`git --work-tree=../ ls-tree` prints nothing at all.\n\n`git --work-tree=.. status` seems to behave mostly as it should\n(reporting all files as having been deleted since the directory is\nmostly empty),\nbut strangely reports the current directory (./) as an untracked file.\nIt correctly reports any other files in the parent directory as\nuntracked,\nthough it excludes the git repository itself from the list. It also\nreported the paths of the files strangely,\nprefixing them with ../ (or multiple ../ segments if the passed\n--work-tree was several levels up).\nThis never happened with any other paths.\n\n`git --work-tree=.. checkout <branch>` seems to write out the index\nand working directory correctly, but while testing it would\nsometimes update HEAD and sometimes not.\n\n`git --work-tree=.. checkout [branch/treeish] -- <files>` completely\nrefused to work, always saying \"pathspec did not match any files\",\neven for dot (.) and catch-all patterns.\n\nThis happens both with regular and bare repositories, and in all\nrepositories that I tested with.\n\nI am using git 2.43.0 through the Arch Linux distribution.\nMy git configuration doesn't change any settings related to paths and\ndirectories.\n\nI apologize if this email is formatted suboptimally.\nThank you for your time.\n"}]}