{"thread":{"id":"62345","subject":"core.hooksPath cannot revert to the default locally","startedAt":"2024-10-16T06:26:24Z","lastAt":"2024-10-17T00:36:30Z","messageCount":5,"participants":["Sam Newbold","Phillip Wood","Taylor Blau"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"505235","messageId":"20241016022613.37813826@scaldcrow","threadId":"62345","inReplyTo":null,"subject":"core.hooksPath cannot revert to the default locally","fromName":"Sam Newbold","fromEmail":"sam@rwsh.org","sentAt":"2024-10-16T06:26:13Z","receivedAt":"2024-10-16T06:26:24Z","isPatch":false,"sender":{"key":"sam@rwsh.org","avatar":null},"body":"From my testing, reading the documentation and hunting through the\nsource code, it appears that if a system administrator sets the\n--system core.hooksPath or a script over which you have limited control\nsets the --global core.hooksPath, then there is no way for an\nindividual repository to configure --local core.hooksPath to get the\ndefault behavior. The naive solution of setting core.hooksPath to be\n.git/hooks breaks in the case of worktrees.\n\nI would be happy to code a patch for this if I knew how it should be\nconfigured. Obviously, no local setting for a config variable is meant\nto inherit the global or system value. We can go all \"set of the null\nset\" by making the empty string mean \"revert to default\". We could go\nfancy \"I know what you really mean\" by interpreting \".git/hooks\" (or\nperhaps any path beginning with \".git\") not literally in the case of\nworktrees, but as relative to GIT_DIR. Or there could be another\nsetting set on a local repository to ignore global and system values of\ncore.hooksPath.\n\nThank you,\nSam Newbold\n"},{"id":"505257","messageId":"dea863c3-7b54-4f8d-b6b0-6087b4cb1abe@gmail.com","threadId":"62345","inReplyTo":"20241016022613.37813826@scaldcrow","subject":"Re: core.hooksPath cannot revert to the default locally","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2024-10-16T09:03:25Z","receivedAt":"2024-10-16T09:03:28Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Sam\n\nOn 16/10/2024 07:26, Sam Newbold wrote:\n>  From my testing, reading the documentation and hunting through the\n> source code, it appears that if a system administrator sets the\n> --system core.hooksPath or a script over which you have limited control\n> sets the --global core.hooksPath, then there is no way for an\n> individual repository to configure --local core.hooksPath to get the\n> default behavior. The naive solution of setting core.hooksPath to be\n> .git/hooks breaks in the case of worktrees.\n\nI'm pretty sure I've used \"git -c core.hookspath=/dev/null ...\" in the \npast when I've wanted to temporarily disable my hooks path, I can't find \nanything in the documentation though. If\n\n     git config core.hookspath /dev/null\n\ndoes work for you it would be really helpful to update the documentation.\n\nBest Wishes\n\nPhillip\n\n> I would be happy to code a patch for this if I knew how it should be\n> configured. Obviously, no local setting for a config variable is meant\n> to inherit the global or system value. We can go all \"set of the null\n> set\" by making the empty string mean \"revert to default\". We could go\n> fancy \"I know what you really mean\" by interpreting \".git/hooks\" (or\n> perhaps any path beginning with \".git\") not literally in the case of\n> worktrees, but as relative to GIT_DIR. Or there could be another\n> setting set on a local repository to ignore global and system values of\n> core.hooksPath.\n> \n> Thank you,\n> Sam Newbold\n> \n\n"},{"id":"505264","messageId":"932d1aab-26e8-4c27-a3dd-a7191e8e71dd@gmail.com","threadId":"62345","inReplyTo":"dea863c3-7b54-4f8d-b6b0-6087b4cb1abe@gmail.com","subject":"Re: core.hooksPath cannot revert to the default locally","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2024-10-16T13:42:57Z","receivedAt":"2024-10-16T13:42:59Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 16/10/2024 10:03, Phillip Wood wrote:\n> I'm pretty sure I've used \"git -c core.hookspath=/dev/null ...\"\n\nLooking at the code that will unfortunately disable all hooks including\nthe ones in .git/hooks. It would make sense to allow an empty\ncore.hooksPath mean \"use .git/hooks\". If you're interested in working\non this then I think doing something like\n\ndiff --git a/config.c b/config.c\nindex a11bb85da30..91f190a1ce1 100644\n--- a/config.c\n+++ b/config.c\n@@ -1437,7 +1437,10 @@ static int git_default_core_config(const char *var, const char *value,\n  \n          if (!strcmp(var, \"core.hookspath\")) {\n                  FREE_AND_NULL(git_hooks_path);\n-                return git_config_pathname(&git_hooks_path, var, value);\n+                if (value)\n+                        return git_config_pathname(&git_hooks_path, var, value);\n+                else\n+                        return 0;\n          }\n  \n          if (!strcmp(var, \"core.bare\")) {\n\nwould be a good starting point\n\nBest Wishes\n\nPhillip\n\n> in the \n> past when I've wanted to temporarily disable my hooks path, I can't find \n> anything in the documentation though. If\n> \n>      git config core.hookspath /dev/null\n> \n> does work for you it would be really helpful to update the documentation.\n> \n> Best Wishes\n> \n> Phillip\n> \n>> I would be happy to code a patch for this if I knew how it should be\n>> configured. Obviously, no local setting for a config variable is meant\n>> to inherit the global or system value. We can go all \"set of the null\n>> set\" by making the empty string mean \"revert to default\". We could go\n>> fancy \"I know what you really mean\" by interpreting \".git/hooks\" (or\n>> perhaps any path beginning with \".git\") not literally in the case of\n>> worktrees, but as relative to GIT_DIR. Or there could be another\n>> setting set on a local repository to ignore global and system values of\n>> core.hooksPath.\n>>\n>> Thank you,\n>> Sam Newbold\n>>\n> \n\n"},{"id":"505296","messageId":"ZxAjLrrqM5i2kdBz@nand.local","threadId":"62345","inReplyTo":"932d1aab-26e8-4c27-a3dd-a7191e8e71dd@gmail.com","subject":"Re: core.hooksPath cannot revert to the default locally","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-16T20:33:50Z","receivedAt":"2024-10-16T20:33:54Z","isPatch":false,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Oct 16, 2024 at 02:42:57PM +0100, Phillip Wood wrote:\n> On 16/10/2024 10:03, Phillip Wood wrote:\n> > I'm pretty sure I've used \"git -c core.hookspath=/dev/null ...\"\n>\n> Looking at the code that will unfortunately disable all hooks including\n> the ones in .git/hooks. It would make sense to allow an empty\n> core.hooksPath mean \"use .git/hooks\". If you're interested in working\n> on this then I think doing something like\n\nThanks for providing a helpful suggestion.\n\nI agree that the behavior you suggested here when specifying an empty\nvalue for 'core.hooksPath' would be an improvement here as a means to\noverride system/global-level configuration.\n\n> diff --git a/config.c b/config.c\n> index a11bb85da30..91f190a1ce1 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -1437,7 +1437,10 @@ static int git_default_core_config(const char *var, const char *value,\n>          if (!strcmp(var, \"core.hookspath\")) {\n>                  FREE_AND_NULL(git_hooks_path);\n> -                return git_config_pathname(&git_hooks_path, var, value);\n> +                if (value)\n\nI think this should read \"if (value && *value)\" instead, to ensure that\nthings like:\n\n    git -c core.hooksPath= ...\n\nwork as expected.\n\nThanks,\nTaylor\n"},{"id":"505319","messageId":"38af2f33-f793-46f8-a0a0-c63ab70e764e@app.fastmail.com","threadId":"62345","inReplyTo":"ZxAjLrrqM5i2kdBz@nand.local","subject":"Re: core.hooksPath cannot revert to the default locally","fromName":"Sam Newbold","fromEmail":"sam@rwsh.org","sentAt":"2024-10-17T00:36:08Z","receivedAt":"2024-10-17T00:36:30Z","isPatch":false,"sender":{"key":"sam@rwsh.org","avatar":null},"body":"Great! I'll reply to this thread when I have some code to be reviewed.\n\nOn Wed, Oct 16, 2024, at 16:33, Taylor Blau wrote:\n> On Wed, Oct 16, 2024 at 02:42:57PM +0100, Phillip Wood wrote:\n>> On 16/10/2024 10:03, Phillip Wood wrote:\n>> > I'm pretty sure I've used \"git -c core.hookspath=/dev/null ...\"\n>>\n>> Looking at the code that will unfortunately disable all hooks including\n>> the ones in .git/hooks. It would make sense to allow an empty\n>> core.hooksPath mean \"use .git/hooks\". If you're interested in working\n>> on this then I think doing something like\n>\n> Thanks for providing a helpful suggestion.\n>\n> I agree that the behavior you suggested here when specifying an empty\n> value for 'core.hooksPath' would be an improvement here as a means to\n> override system/global-level configuration.\n>\n>> diff --git a/config.c b/config.c\n>> index a11bb85da30..91f190a1ce1 100644\n>> --- a/config.c\n>> +++ b/config.c\n>> @@ -1437,7 +1437,10 @@ static int git_default_core_config(const char *var, const char *value,\n>>          if (!strcmp(var, \"core.hookspath\")) {\n>>                  FREE_AND_NULL(git_hooks_path);\n>> -                return git_config_pathname(&git_hooks_path, var, value);\n>> +                if (value)\n>\n> I think this should read \"if (value && *value)\" instead, to ensure that\n> things like:\n>\n>     git -c core.hooksPath= ...\n>\n> work as expected.\n>\n> Thanks,\n> Taylor\n"}]}