On Tue, Aug 24 2021, Randall S. Becker wrote: > On August 24, 2021 4:12 PM, Ævar Arnfjörð Bjarmason wrote: >>On Wed, Aug 18 2021, Emily Shaffer wrote: >> >>> Since hooks can now be supplied via the config, and a config can be >>> present without a gitdir via the global and system configs, we can >>> start to allow 'git hook run' to occur without a gitdir. This enables >>> us to do things like run sendemail-validate hooks when running 'git send-email' >>> from a nongit directory. >> >>Sensible goal. Perhaps we should note in an earlier commit when config-based hooks are introduced something like: > > To clarify the requirements here, if running without a gitdir (and > thus without a repository?) how will front-ends know what to supply? > Will this just be "some shell script" that runs? Emily's also aiming to have "git hook run" running "some shell script", but in this case we're talking about any git program that runs hooks, but doesn't require a repo. I think the only one is git-send-email's sendemail-validate hook. >> >> Even though we've added config-based hooks, they currently only work >> if we can find a .git directory, even though certain commands such >> as "git send-email" (or only that command?) can be run outside of a >> git directory. A subsequent commit will address that edge-case. > > So we cannot assume anything about the repository, correct? Similar to running git version but not git status? Right, with RUN_SETUP_GENTLY we may not have a repo at all, so like commands such as "git bundle", "git config", "git ls-remote" etc. >>> [...] >>> Notes: >>> For hookdir hooks, do we want to run them in nongit dir when core.hooksPath >>> is set? For example, if someone set core.hooksPath in their global config and >>> then ran 'git hook run sendemail-validate' in a nongit dir? > > So this is complete consent to run outside of git? I wonder whether > there needs to be an attribute associated with the hook that enables > this edge capability. That way we can validate whether the hook should > be run or not (from front-end scripts). If I understand you correctly you're pointing out that anyone with a sendemail-validate script could previously have assumed a repo, but not anymore. So e.g. someone who always has other config the hook requires when they run it in repository might unexpectedly have that hook fail if they naïvely set the config for that sendemail-validate hook via "git config --global". I think that's a good point, and one I hadn't really considered. I think it's probably best to just document this edge case for the one (or few?) hooks that have this caveat than to not support it. I.e. it seems useful to have a sendemail-validate without a repo (just to parse/validate the about-to-be-sent-email), that we needed a repo before was really only an emergent effect. Also, I think it's not new with this config-based hook mechanism, but something that I introduced in back when I added core.hooksPath (but I don't think I realized I was adding this edge case at the time).