{"thread":{"id":"48600","subject":"some (fairly simple) questions about hooks","startedAt":"2018-05-30T11:02:43Z","lastAt":"2018-05-30T11:14:32Z","messageCount":2,"participants":["Robert P. J. Day","Ævar Arnfjörð Bjarmason"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"348801","messageId":"alpine.LFD.2.21.1805300700190.7958@localhost.localdomain","threadId":"48600","inReplyTo":null,"subject":"some (fairly simple) questions about hooks","fromName":"Robert P. J. Day","fromEmail":"rpjday@crashcourse.ca","sentAt":"2018-05-30T11:00:36Z","receivedAt":"2018-05-30T11:02:43Z","isPatch":false,"sender":{"key":"rpjday@crashcourse.ca","avatar":"https://avatars.githubusercontent.com/u/226084077?v=4"},"body":"\n  just want to clarify a few things about hooks to make sure i'm not\nmissing anything when i write my own hooks tutorial.\n\n  first, for any hook to be active, it *must* be marked as executable\n-- that much seems clear from the man page.\n\n  next, \"core.hooksPath\" aside, the hooks related to any repository\nare (by default) in $GIT_DIR/hooks and *only* in that directory. AIUI,\nthere is no way to extend or enhance the per-repo hooks with, perhaps,\na common subset of hooks in a common directory, is there? (i'm\nignoring the possibility that one could populate $GIT_DIR/hooks with a\nfew symlinks to share some common hooks among a number of repos --\nwould that work? and is it something that is even considered good\nprogramming practice?)\n\n  next, AIUI, the use of \"core.hooksPath\" *completely* overrides any\nhooks in $GIT_DIR/hooks, yes? that is, that config setting does not\nsupport any sort of enhancement of existing hooks, it's all or\nnothing, correct?\n\n  and sticking with core.hooksPath, one could set it either globally\nto affect all repos, or one could of course set it locally to take\nadvantage of it just for *some* repos, but not all of them.\n\n  finally, if you run \"git init\" for an existing repo, as i read it,\nbased on the templates content in effect, that will install new hooks\nin a repo but *only* hooks for which there is no existing equivalent\n-- it will *never* overwrite an existing hook by the same name.\n\n  oh, and related to that last paragraph, running \"git init\" related\nto hooks should be unaffected by core.hooksPath, is that correct? so\nthat even if \"git init\" installs some new hooks in an existing repo,\nthose new hooks will have no effect if core.hooksPath is set to refer\nsomewhere else, yes?\n\n  am i missing any important features of hooks in the above?\n\nrday\n\n-- \n\n========================================================================\nRobert P. J. Day                                 Ottawa, Ontario, CANADA\n                  http://crashcourse.ca/dokuwiki\n\nTwitter:                                       http://twitter.com/rpjday\nLinkedIn:                               http://ca.linkedin.com/in/rpjday\n========================================================================\n"},{"id":"348802","messageId":"877enlflaa.fsf@evledraar.gmail.com","threadId":"48600","inReplyTo":"alpine.LFD.2.21.1805300700190.7958@localhost.localdomain","subject":"Re: some (fairly simple) questions about hooks","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-05-30T11:14:05Z","receivedAt":"2018-05-30T11:14:32Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, May 30 2018, Robert P. J. Day wrote:\n\n>   just want to clarify a few things about hooks to make sure i'm not\n> missing anything when i write my own hooks tutorial.\n>\n>   first, for any hook to be active, it *must* be marked as executable\n> -- that much seems clear from the man page.\n\nYes.\n\n>   next, \"core.hooksPath\" aside, the hooks related to any repository\n> are (by default) in $GIT_DIR/hooks and *only* in that directory. AIUI,\n> there is no way to extend or enhance the per-repo hooks with, perhaps,\n> a common subset of hooks in a common directory, is there? (i'm\n> ignoring the possibility that one could populate $GIT_DIR/hooks with a\n> few symlinks to share some common hooks among a number of repos --\n> would that work? and is it something that is even considered good\n> programming practice?)\n\nYes. There's git-native no way to have N number of the same type of\nhooks. core.hooksPath is all or nothing.\n\nSee https://public-inbox.org/git/877eqqnq22.fsf@evledraar.gmail.com/ for\nsome musings of mine about potential future plans here & workarounds in\nplace in the wild, e.g. GitLab's support for N number of server-side\nhooks.\n\nYou can also use e.g. the \"pee\" utility frome moreutils\n(https://joeyh.name/code/moreutils/) to accomplish the same thing.\n\n>   next, AIUI, the use of \"core.hooksPath\" *completely* overrides any\n> hooks in $GIT_DIR/hooks, yes? that is, that config setting does not\n> support any sort of enhancement of existing hooks, it's all or\n> nothing, correct?\n\nYes.\n\n>   and sticking with core.hooksPath, one could set it either globally\n> to affect all repos, or one could of course set it locally to take\n> advantage of it just for *some* repos, but not all of them.\n\nYes, this is not special to core.hooksPath but (almost) all config\nvariables (aside from stuff like per-remote config which can't be set\nglobally).\n\n>   finally, if you run \"git init\" for an existing repo, as i read it,\n> based on the templates content in effect, that will install new hooks\n> in a repo but *only* hooks for which there is no existing equivalent\n> -- it will *never* overwrite an existing hook by the same name.\n\nYes \"git init\" can re-initialize an existing repo, but will not clobber\nexisting stuff (or shouldn't).\n\n>   oh, and related to that last paragraph, running \"git init\" related\n> to hooks should be unaffected by core.hooksPath, is that correct? so\n> that even if \"git init\" installs some new hooks in an existing repo,\n> those new hooks will have no effect if core.hooksPath is set to refer\n> somewhere else, yes?\n\nYes \"git init\" will just inject the hooks into .git/hooks, because it\ndoesn't care about hooks, it's just re-injecting stuff found in the\ntemplate dir, and the \"hooks\" dir is just one of the things that happens\nto exist there.\n\n>   am i missing any important features of hooks in the above?\n\nNot that I can think of.\n"}]}