Run global hooks from the directory at hooks.dir
PATCH v3 1/1 Run global hooks from the directory at hooks.dir
Run global hooks in the directory specified by the config variable hooks.dir before every attempt at running a local hook. If the global hook fails, the local hook will not run. If the global hook is absent, the local hook runs normally. This is useful because it means you can have scripts that run as hooks for multiple repositories, for example coding style enforcement for an entire organization, or system-wide commit analytics.
---
The possibility of adding this feature was previously discussed here:
http://marc.info/?l=git&m=127808782807807&w=2
Fixed some bad whitespace in contrib/completion/git-completion.bash
Fixed errors pointed out by Johannes Sixt
Cheers,
Brian
Documentation/config.txt | 5 ++ cache.h | 2 + config.c | 12 ++++ contrib/completion/git-completion.bash | 1 + run-command.c | 52 +++++++++++++----- t/t7510-global-hooks.sh | 88 ++++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+), 15 deletions(-) create mode 100755 t/t7510-global-hooks.sh
Documentation/config.txt +5 -0
@@ -1199,6 +1199,11 @@ help.autocorrect:: value is 0 - the command will be just shown but not executed. This is the default. +hooks.dir:: + Directory containing executable hooks. Usage is identical to + .git/hooks except they are triggered for any repository used + while this configuration is set. + http.proxy:: Override the HTTP proxy, normally configured using the 'http_proxy' environment variable (see linkgit:curl[1]). This can be overridden
cache.h +2 -0
@@ -1018,6 +1018,8 @@ extern const char *git_commit_encoding;extern const char *git_log_output_encoding;extern const char *git_mailmap_file; +extern const char *git_hooks_dir; +/* IO helper functions */ extern void maybe_flush_or_die (FILE *,const char *);extern int copy_fd (int ifd,int ofd);
config.c +12 -0
@@ -745,6 +745,15 @@ static int git_default_mailmap_config(const char *var, const char *value)return 0 ; } +static int git_default_hooks_config (const char *var,const char *value) +{ +if (!strcmp (var,"hooks.dir" )) +return git_config_pathname (&git_hooks_dir, var, value); + +/* Add other config variables here and to Documentation/config.txt. */ +return 0 ; +} +int git_default_config (const char *var,const char *value,void *dummy) {if (!prefixcmp (var,"core." ))
@@ -768,6 +777,9 @@ int git_default_config(const char *var, const char *value, void *dummy)if (!prefixcmp (var,"advice." ))return git_default_advice_config (var, value); +if (!prefixcmp (var,"hooks." )) +return git_default_hooks_config (var, value); +if (!strcmp (var,"pager.color" ) || !strcmp (var,"color.pager" )) { pager_use_color =git_config_bool (var,value);return 0 ;
contrib/completion/git-completion.bash +1 -0
@@ -1913,6 +1913,7 @@ _git_config () help.autocorrect help.browser help.format + hooks.dir http.lowSpeedLimit http.lowSpeedTime http.maxRequests
run-command.c +37 -15
76 lines not on this page · raw message
t/t7510-global-hooks.sh new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
1.7.3.2.162.g4671