3 test_description
='test installation of pre-commit hook'
12 test -s "${1:-.}/.git/info/attributes" &&
13 test -s "${1:-.}/.git/hooks/pre-commit" &&
14 test -x "${1:-.}/.git/hooks/pre-commit" &&
15 gcmd_
="$(git -C "${1:-.}" config merge.ours.driver)" &&
16 test z
"$gcmd_" = z
"touch %A"
20 test ! -e "${1:-.}/.git/info/attributes" &&
21 test ! -e "${1:-.}/.git/hooks/pre-commit" &&
22 test_must_fail git
-C "${1:-.}" config merge.ours.driver
25 has_no_tg_setup_bare
() {
26 test ! -e "${1:-.}/info/attributes" &&
27 test ! -e "${1:-.}/hooks/pre-commit" &&
28 test_must_fail git
-C "${1:-.}" config merge.ours.driver
31 test_expect_success
'setup_ours' '
32 tab=" " && # single tab character in quotes
33 test_create_repo r1 &&
34 test ! -e r1/.git/info/attributes &&
35 tg_test_include -C r1 &&
36 cd r1 && setup_ours && cd .. &&
37 test -f r1/.git/info/attributes &&
38 test -r r1/.git/info/attributes &&
39 grep -q "^[.]topmsg[ $tab][ $tab]*merge=ours$" r1/.git/info/attributes &&
40 grep -q "^[.]topdeps[ $tab][ $tab]*merge=ours$" r1/.git/info/attributes &&
41 gcmn="$(git -C r1 config merge.ours.name)" &&
43 gcmd="$(git -C r1 config merge.ours.driver)" &&
44 test -n "$gcmd" && test z"$gcmd" = z"touch %A" &&
45 test ! -e r1/.git/hooks/pre-commit &&
49 test_expect_success
'setup_hook pre-commit' '
50 test_create_repo r2 &&
51 test ! -e r2/.git/hooks/pre-commit &&
52 tg_test_include -C r2 &&
53 cd r2 && setup_hook "pre-commit" && cd .. &&
54 test -f r2/.git/hooks/pre-commit &&
55 test -x r2/.git/hooks/pre-commit &&
56 sed -n 1p <r2/.git/hooks/pre-commit | grep -q "^#!" &&
57 grep -F -q "${0##*/}" r2/.git/hooks/pre-commit &&
58 grep -F -q "/pre-commit" r2/.git/hooks/pre-commit &&
59 test $(wc -l <r2/.git/hooks/pre-commit) -eq 2 &&
60 test ! -e r2/.git/info/attributes &&
61 test_must_fail git -C r2 config merge.ours.name &&
62 test_must_fail git -C r2 config merge.ours.driver &&
101 tg_cmd_will_setup
() {
103 --version|
--status|
--hooks-path|
--exec-path|
--awk-path|
--top-bases| \
104 base|contains|
export|files|info|log|
mail|next|
patch|prev|rebase|revert|shell|status|st|summary|tag|version
)
110 test_expect_success
'no setup happens for help' '
111 test_create_repo r3 && cd r3 &&
112 say "# checking tg help variations" &&
113 test_might_fail tg && has_no_tg_setup &&
114 test_might_fail tg -h && has_no_tg_setup &&
115 test_might_fail tg --help && has_no_tg_setup &&
116 test_might_fail tg --bogus && has_no_tg_setup &&
117 for cmd in $TG_CMDS; do
118 say "# checking tg $cmd help variations" &&
119 test_might_fail </dev/null tg $cmd -h && has_no_tg_setup &&
120 test_might_fail </dev/null tg $cmd --help && has_no_tg_setup
126 test_expect_success
'no setup happens for exempted commands' '
127 test_create_repo r4 && cd r4 &&
128 for cmd in $TG_CMDS; do
129 if ! tg_cmd_will_setup "$cmd"; then
130 say "# checking tg $cmd does not do setup"
131 test_might_fail </dev/null tg $cmd && has_no_tg_setup &&
132 test_might_fail </dev/null tg $cmd --bogus-option-here && has_no_tg_setup
139 for cmd
in $TG_CMDS; do
140 if tg_cmd_will_setup
"$cmd"; then
141 test_expect_success
"setup happens for tg $cmd" '
142 rm -rf rt && test_create_repo rt && cd rt &&
144 test_might_fail </dev/null tg $cmd &&
145 test_might_fail </dev/null tg $cmd --bogus-option-here &&
152 test_expect_success
'no setup happens in bare repository' '
153 git init --bare r5 && cd r5 &&
154 for cmd in $TG_CMDS; do
155 say "# checking tg $cmd does not do setup in bare repo"
156 test_might_fail </dev/null tg $cmd && has_no_tg_setup_bare &&
157 test_might_fail </dev/null tg $cmd --bogus-option-here && has_no_tg_setup_bare
159 has_no_tg_setup_bare &&