File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -351,6 +351,9 @@ advice.*::
351351 addEmbeddedRepo::
352352 Advice on what to do when you've accidentally added one
353353 git repo inside of another.
354+ ignoredHook::
355+ Advice shown if an hook is ignored because the hook is not
356+ set as executable.
354357--
355358
356359core.fileMode::
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ int advice_set_upstream_failure = 1;
1717int advice_object_name_warning = 1 ;
1818int advice_rm_hints = 1 ;
1919int advice_add_embedded_repo = 1 ;
20+ int advice_ignored_hook = 1 ;
2021
2122static struct {
2223 const char * name ;
@@ -38,6 +39,7 @@ static struct {
3839 { "objectnamewarning" , & advice_object_name_warning },
3940 { "rmhints" , & advice_rm_hints },
4041 { "addembeddedrepo" , & advice_add_embedded_repo },
42+ { "ignoredhook" , & advice_ignored_hook },
4143
4244 /* make this an alias for backward compatibility */
4345 { "pushnonfastforward" , & advice_push_update_rejected }
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ extern int advice_set_upstream_failure;
1919extern int advice_object_name_warning ;
2020extern int advice_rm_hints ;
2121extern int advice_add_embedded_repo ;
22+ extern int advice_ignored_hook ;
2223
2324int git_default_advice_config (const char * var , const char * value );
2425__attribute__((format (printf , 1 , 2 )))
Original file line number Diff line number Diff line change @@ -2350,6 +2350,7 @@ _git_config ()
23502350 advice.rmHints
23512351 advice.statusHints
23522352 advice.statusUoption
2353+ advice.ignoredHook
23532354 alias.
23542355 am.keepcr
23552356 am.threeWay
Original file line number Diff line number Diff line change 55#include "argv-array.h"
66#include "thread-utils.h"
77#include "strbuf.h"
8+ #include "string-list.h"
89
910void child_process_init (struct child_process * child )
1011{
@@ -1169,11 +1170,28 @@ const char *find_hook(const char *name)
11691170 strbuf_reset (& path );
11701171 strbuf_git_path (& path , "hooks/%s" , name );
11711172 if (access (path .buf , X_OK ) < 0 ) {
1173+ int err = errno ;
1174+
11721175#ifdef STRIP_EXTENSION
11731176 strbuf_addstr (& path , STRIP_EXTENSION );
11741177 if (access (path .buf , X_OK ) >= 0 )
11751178 return path .buf ;
1179+ if (errno == EACCES )
1180+ err = errno ;
11761181#endif
1182+
1183+ if (err == EACCES && advice_ignored_hook ) {
1184+ static struct string_list advise_given = STRING_LIST_INIT_DUP ;
1185+
1186+ if (!string_list_lookup (& advise_given , name )) {
1187+ string_list_insert (& advise_given , name );
1188+ advise (_ ("The '%s' hook was ignored because "
1189+ "it's not set as executable.\n"
1190+ "You can disable this warning with "
1191+ "`git config advice.ignoredHook false`." ),
1192+ path .buf );
1193+ }
1194+ }
11771195 return NULL ;
11781196 }
11791197 return path .buf ;
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ test_description=' ignored hook warning'
4+
5+ . ./test-lib.sh
6+
7+ test_expect_success setup '
8+ hookdir="$(git rev-parse --git-dir)/hooks" &&
9+ hook="$hookdir/pre-commit" &&
10+ mkdir -p "$hookdir" &&
11+ write_script "$hook" <<-\EOF
12+ exit 0
13+ EOF
14+ '
15+
16+ test_expect_success ' no warning if hook is not ignored' '
17+ git commit --allow-empty -m "more" 2>message &&
18+ test_i18ngrep ! -e "hook was ignored" message
19+ '
20+
21+ test_expect_success POSIXPERM ' warning if hook is ignored' '
22+ chmod -x "$hook" &&
23+ git commit --allow-empty -m "even more" 2>message &&
24+ test_i18ngrep -e "hook was ignored" message
25+ '
26+
27+ test_expect_success POSIXPERM ' no warning if advice.ignoredHook set to false' '
28+ test_config advice.ignoredHook false &&
29+ chmod -x "$hook" &&
30+ git commit --allow-empty -m "even more" 2>message &&
31+ test_i18ngrep ! -e "hook was ignored" message
32+ '
33+
34+ test_expect_success ' no warning if unset advice.ignoredHook and hook removed' '
35+ rm -f "$hook" &&
36+ test_unconfig advice.ignoredHook &&
37+ git commit --allow-empty -m "even more" 2>message &&
38+ test_i18ngrep ! -e "hook was ignored" message
39+ '
40+
41+ test_done
You can’t perform that action at this time.
0 commit comments