{"thread":{"id":"60949","subject":"Why does the includeif woks how it does?","startedAt":"2024-02-18T15:37:31Z","lastAt":"2024-02-20T01:42:48Z","messageCount":4,"participants":["Dominik von Haller","brian m. carlson","rsbecker@nexbridge.com","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"488876","messageId":"FR2P281MB1686B7258CFB60A0F33FE108BA522@FR2P281MB1686.DEUP281.PROD.OUTLOOK.COM","threadId":"60949","inReplyTo":null,"subject":"Why does the includeif woks how it does?","fromName":"Dominik von Haller","fromEmail":"vonhaller@fastec.de","sentAt":"2024-02-18T15:37:29Z","receivedAt":"2024-02-18T15:37:31Z","isPatch":false,"sender":{"key":"vonhaller@fastec.de","avatar":null},"body":"Hi,\n\n\nI have been playing around with the includeif from the .gitconfig. It did not work for me at first, but after some help, I did get it to work.\n\nIf you are curious. My Problem and what else was discussed here: https://github.com/git-for-windows/git/issues/4823\n\nAnyway. So, I was trying to access the email property which was set through an includeif config. It did not work because I was in a non git directory. Yes, I do know that the property set in includeif is named gitdir, but it was not obvious to me that you need to be in a git tracked directory for it to work.\n\nI am trying to understand why it must be this way. Why does it not work in non git tracked directories?\n\nI am not sure if I am conveying my Question correctly. Please read the messages in the github issue if the content of this email was confusing.\n\n\nBest regards\nDominik von Haller\n"},{"id":"488925","messageId":"ZdO1oL73SF5ZKOJT@tapette.crustytoothpaste.net","threadId":"60949","inReplyTo":"FR2P281MB1686B7258CFB60A0F33FE108BA522@FR2P281MB1686.DEUP281.PROD.OUTLOOK.COM","subject":"Re: Why does the includeif woks how it does?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-02-19T20:10:08Z","receivedAt":"2024-02-19T20:10:16Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2024-02-18 at 15:37:29, Dominik von Haller wrote:\n> I have been playing around with the includeif from the .gitconfig. It did not work for me at first, but after some help, I did get it to work.\n> \n> If you are curious. My Problem and what else was discussed here: https://github.com/git-for-windows/git/issues/4823\n> \n> Anyway. So, I was trying to access the email property which was set through an includeif config. It did not work because I was in a non git directory. Yes, I do know that the property set in includeif is named gitdir, but it was not obvious to me that you need to be in a git tracked directory for it to work.\n> \n> I am trying to understand why it must be this way. Why does it not work in non git tracked directories?\n\nThe main reason it works this way is because the goal is to adjust\nconfiguration based on the location of a repository.  Thus, if I have\n`~/checkouts/work/` with my work code and `~/checkouts/personal/` with\nmy personal code, I can set options that are appropriate in each case\n(e.g., `user.email`, `user.signingkey`, `credential.helper`, etc.).\n\nAlso, except for reading and writing with `git config`, the\nconfiguration is typically not used unless you're in a repository.\nThere are only a handful of Git commands that don't use a repository at\nall, so usually setting configuration outside of a repository isn't very\nuseful.\n\nNote that if it didn't require a repository, then it would have to work\non the current working directory.  But, it should be noted, the gitdir\noption specifically does not operate on the current working directory.\nWhile it is customary to have one's working directory be inside the\nrepository, you can be elsewhere and use `git -C` to change into the\nrepository (internally, Git does indeed change the working directory,\nbut that's an implementation detail).\n\nThat's not to say a feature couldn't be added that operated based on the\ncurrent working directory (or some related constraint) instead, but no\nsuch feature has been added.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"488927","messageId":"01d401da6379$635fdb30$2a1f9190$@nexbridge.com","threadId":"60949","inReplyTo":"ZdO1oL73SF5ZKOJT@tapette.crustytoothpaste.net","subject":"RE: Why does the includeif woks how it does?","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2024-02-19T21:19:51Z","receivedAt":"2024-02-19T21:20:16Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On Monday, February 19, 2024 3:10 PM, brian m. carlson wrote:\n>On 2024-02-18 at 15:37:29, Dominik von Haller wrote:\n>> I have been playing around with the includeif from the .gitconfig. It did not work\n>for me at first, but after some help, I did get it to work.\n>>\n>> If you are curious. My Problem and what else was discussed here:\n>> https://github.com/git-for-windows/git/issues/4823\n>>\n>> Anyway. So, I was trying to access the email property which was set through an\n>includeif config. It did not work because I was in a non git directory. Yes, I do know\n>that the property set in includeif is named gitdir, but it was not obvious to me that\n>you need to be in a git tracked directory for it to work.\n>>\n>> I am trying to understand why it must be this way. Why does it not work in non git\n>tracked directories?\n>\n>The main reason it works this way is because the goal is to adjust configuration\n>based on the location of a repository.  Thus, if I have `~/checkouts/work/` with my\n>work code and `~/checkouts/personal/` with my personal code, I can set options\n>that are appropriate in each case (e.g., `user.email`, `user.signingkey`,\n>`credential.helper`, etc.).\n>\n>Also, except for reading and writing with `git config`, the configuration is typically\n>not used unless you're in a repository.\n>There are only a handful of Git commands that don't use a repository at all, so\n>usually setting configuration outside of a repository isn't very useful.\n>\n>Note that if it didn't require a repository, then it would have to work on the current\n>working directory.  But, it should be noted, the gitdir option specifically does not\n>operate on the current working directory.\n>While it is customary to have one's working directory be inside the repository, you\n>can be elsewhere and use `git -C` to change into the repository (internally, Git does\n>indeed change the working directory, but that's an implementation detail).\n>\n>That's not to say a feature couldn't be added that operated based on the current\n>working directory (or some related constraint) instead, but no such feature has\n>been added.\n\nI have considered contributing an \"includewhere\" option that would do that and differentiate from \"includeif\". I'm not sure it is required, and what would happen with symbolic links.\n\nJust a thought.\n--Randall\n\n"},{"id":"488948","messageId":"xmqqedd7ykq4.fsf@gitster.g","threadId":"60949","inReplyTo":"01d401da6379$635fdb30$2a1f9190$@nexbridge.com","subject":"Re: Why does the includeif woks how it does?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-02-20T01:42:43Z","receivedAt":"2024-02-20T01:42:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"<rsbecker@nexbridge.com> writes:\n\n> I have considered contributing an \"includewhere\" option that would\n> do that and differentiate from \"includeif\". I'm not sure it is\n> required, and what would happen with symbolic links.\n\nOther potential gotchas would include how it interacts with\ndirectory hierarchies.  You may be inside a directory /a/b (where\nnone of /, /a, and /a/b is controlled by git) and want your \"git\ninit\" invocation to be affected by some configuration included into\nyour $HOME/.gitconfig via include-where mechanism.  Would it work\nrecursively?  In other words, if you had\n\n\t[includeIf \"gitdir:/a/b\"] path = $HOME/gits/a-b-in-repo\n\n\t[includeIf \"cwd:/\"] path = $HOME/gits/others\n\t[includeIf \"cwd:/a\"] path = $HOME/gits/a\n\t[includeIf \"cwd:/a/b\"] path = $HOME/gits/a-b\n\nwould all of them be included?  Just the last one?  Does the most\nspecific one win?\n\nAfter your \"git init\" succeeds, the one specified with gitdir: would\nstart kicking in.  Would the \"cwd:\" ones that are meant for cases\noutside any directory under Git control be ignored then?\n\nI am not opposed to such a feature existing at all; just pointing\nout there are sources of end-user confusion we need to be careful\nwhile we design the feature.\n\n"}]}