{"thread":{"id":"61417","subject":"[Bug Report] git config includeIf not traversing symlink subdirectories","startedAt":"2024-05-03T21:32:11Z","lastAt":"2024-05-04T01:06:38Z","messageCount":3,"participants":["Simon Thurston","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"494066","messageId":"CAKx51amU_c9EU+573RWDc0+w3V2u5TSk+mQhts1gYyKRhxGCzQ@mail.gmail.com","threadId":"61417","inReplyTo":null,"subject":"[Bug Report] git config includeIf not traversing symlink subdirectories","fromName":"Simon Thurston","fromEmail":"simongethurston@gmail.com","sentAt":"2024-05-03T21:31:59Z","receivedAt":"2024-05-03T21:32:11Z","isPatch":false,"sender":{"key":"simongethurston@gmail.com","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\nOn Windows. Create a directory. Configre a gitconfig file to includeIf\ngitdir that directory. Add any configuration you wish to the gitconfig\nfile pointed to by the includeif path. Inside the created directory,\ncreate a symlink to a UNC Path/Network location. Change directory into\nthe symlinked directory. Run git config --show-origin on a configured\nvalue.\n\nWhat did you expect to happen? (Expected behavior)\nThe value configured in the includeIf path to be found.\n\nWhat happened instead? (Actual behavior)\nNo configuration data found.\n\nWhat's different between what you expected and what actually happened?\nGit seems to be unable to traverse subdirectories that are symlinks to\ninclude any git repositories stored inside them.\n\nAnything else you want to add:\nI am well aware that while running Windows 11 in a corporate\nenvironment there is likely something silly that is stopping me from\ndoing something correctly within our Group Policy. However, I just\nwanted to open a report in case that something is not working. The\nworkaround I had to do for this is to regular include the config file\nI had written, which is not ideal, even though I am pretty sure that\nthe includeIfs I have after it should override it. I am interacting\nwith git through pwsh 7.4.2.\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.45.0.windows.1\ncpu: x86_64\nbuilt from commit: b5d0511969ccd9ab86395c37e5a7619d8b4e7c32\nsizeof-long: 4\nsizeof-size_t: 8\nshell-path: /bin/sh\nfeature: fsmonitor--daemon\nuname: Windows 10.0 22635\ncompiler info: gnuc: 13.2\nlibc info: no libc information available\n$SHELL (typically, interactive shell): <unset>\n\n\n[Enabled Hooks]\n"},{"id":"494068","messageId":"ZjVt5jtC8cKgWpqQ@tapette.crustytoothpaste.net","threadId":"61417","inReplyTo":"CAKx51amU_c9EU+573RWDc0+w3V2u5TSk+mQhts1gYyKRhxGCzQ@mail.gmail.com","subject":"Re: [Bug Report] git config includeIf not traversing symlink subdirectories","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-05-03T23:06:14Z","receivedAt":"2024-05-03T23:06:18Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2024-05-03 at 21:31:59, Simon Thurston wrote:\n> Thank you for filling out a Git bug report!\n> Please answer the following questions to help us understand your issue.\n> \n> What did you do before the bug happened? (Steps to reproduce your issue)\n> On Windows. Create a directory. Configre a gitconfig file to includeIf\n> gitdir that directory. Add any configuration you wish to the gitconfig\n> file pointed to by the includeif path. Inside the created directory,\n> create a symlink to a UNC Path/Network location. Change directory into\n> the symlinked directory. Run git config --show-origin on a configured\n> value.\n\nI've included a shell script below that tries to provide a testcase for\nyour reproduction steps.  Since I'm on Linux, I don't have a UNC drive,\nbut I created a different location outside of the repository called\nother-dir that simulates the same behaviour:\n\n----\n#!/bin/sh\n\ntempdir=$(mktemp -d)\ncd \"$tempdir\"\ncat >config <<EOM\n[includeIf \"gitdir:$tempdir/dir/\"]\n    path = \"$tempdir/other-config\"\nEOM\ncat >other-config <<EOM\n[user]\n    name = \"Foo Bar\"\nEOM\n\nexport GIT_CONFIG_GLOBAL=\"$tempdir/config\"\nmkdir \"$tempdir/dir\"\nmkdir \"$tempdir/other-dir\"\ncd \"$tempdir/dir\"\ngit init -b dev\necho \"In dir ($PWD):\"\ngit config -l --show-origin\nln -s ../other-dir other-dir\ncd other-dir\necho \"In symlink ($PWD):\"\ngit config -l --show-origin\n----\n\n> What did you expect to happen? (Expected behavior)\n> The value configured in the includeIf path to be found.\n> \n> What happened instead? (Actual behavior)\n> No configuration data found.\n> \n> What's different between what you expected and what actually happened?\n> Git seems to be unable to traverse subdirectories that are symlinks to\n> include any git repositories stored inside them.\n\nAssuming my reproduction steps are correct, this is expected.  Git\nalways determines the Git directory by resolving it to an absolute path\ncontaining no symlinks with the equivalent of `realpath` on Linux or\n`GetFinalPathNameByHandle` on Windows.  The fact that your working\ndirectory contains a symlink doesn't mean that the destination of the\nsymlink is part of your repository.  In fact, if the destination of your\nsymlink is on another drive, it cannot be in your repository at all,\nsince Git cannot handle cross-drive repositories at all.  Since it's not\nin the repository, the gitdir pattern won't match.\n\nIf I've misunderstood, could you help me understand better by providing\na small shell script that can reproduce the problem you're seeing, so\nI can provide a better answer?\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"},{"id":"494071","messageId":"ZjWKHJD50PNcWu5R@tapette.crustytoothpaste.net","threadId":"61417","inReplyTo":"B240544D-1695-4627-B7EC-5C9CA7716265@gmail.com","subject":"Re: [Bug Report] git config includeIf not traversing symlink subdirectories","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-05-04T01:06:36Z","receivedAt":"2024-05-04T01:06:38Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"[Please keep the list in CC so others can chime in.]\n\nOn 2024-05-03 at 23:41:14, Simon Thurston wrote:\n> Thanks Brian. The issue I'm having is that I have two main development directories, for \"home\" and for \"work\". I have includeIf statements in my primary .gitconfig that sources different public/private keys for each subdirectory. Under the \"work\" subdirectory, I have folders for projects, and then a \"Deploy\" folder that contains symlinks to folders over the network, so I can quickly cd and git clone/pull to deploy things manually, as well as use with some CD powershell scripts I have. The important thing to note is that the directories that are symlinked to repositories.\n> \n> In short, if I have an includeIf that encompasses a parent directory, any subdirectory symlink that points to a repository on a local server does not properly resolve to include the settings from the includeIf.\n> \n> /work/Project/.git can be detected, but /work/Deploy/ProjectSymlink/.git cannot, and thus any includeIf statement that checks for repositories under /work/** does not properly detect the repositories that are symlinked.\n\nYes, I think this is intentional.  Git doesn't consider the repositories\nwhich are on the UNC drive to be under /work/Deploy, because the\ncanonical path is not in that location.\n\n> I have tried to get around this by adding an extra includeIf statement to include //the/direct/unc/path/** but that was not able to resolve properly either. Mapped network drives with drive letters also don't resolve, and the only workaround I had was to blanket apply the config file to every directory, which is not ideal for the environment I work in.\n\nYes, the mapped network drives will be resolved to the UNC path with\n`GetPathNameByHandle`, which is why that syntax doesn't work.\n\n> If the behavior around symlinks is intentional, then that is fine and can be worked around, but not being able to specify UNC style paths in the configs is something that makes it difficult to work on SMB shares with specific configs needed.\n\nAs I said, I don't use Windows except extremely incidentally, so it's\ndifficult for me to speak with any authority on UNC paths.  It's\npossible that they are supported using a syntax I don't know about, or\nit's possible that they simply don't work at all.  If it's the latter,\nI'm sure we'd accept a patch to fix it.\n\nWhat I might suggest is switching into one of the symlinked directories\nand running `git rev-parse --absolute-git-dir`, which should show you\nwhat Git thinks the directory is.  You can then write that path directly\nin the configuration file, nothing that inside the double quotes,\nbackslashes must be escaped (so if the path is \\\\the\\direct\\unc\\path,\nyou'd write '[includeIf \"\\\\\\\\the\\\\direct\\\\unc\\\\path\"]').  You may also\nwant to use gitdir/i if you're not already, since my guess is that your\npaths are actually case-insensitive.\n\nIf that doesn't work, hopefully someone else more familiar than me with\nWindows can speak more to this.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"}]}