README-TESTLIB-TG: fix typo
[topgit/pro.git] / t / t2000-hook-installation.sh
blobdfe6ea4e80426dbb0a3201f4df92afba4b63e2c6
1 #!/bin/sh
3 test_description='test installation of pre-commit hook'
5 TEST_NO_CREATE_REPO=1
7 . ./test-lib.sh
9 test_plan 14
11 has_tg_setup() {
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"
19 has_no_tg_setup() {
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)" &&
42 test -n "$gcmn" &&
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 &&
46 rm -rf r1
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 &&
63 rm -rf r2
66 TG_CMDS="
67 --version
68 --status
69 --hooks-path
70 --exec-path
71 --awk-path
72 --top-bases
73 annihilate
74 base
75 checkout
76 contains
77 create
78 delete
79 depend
80 export
81 files
82 import
83 info
84 log
85 mail
86 next
87 patch
88 prev
89 push
90 rebase
91 remote
92 revert
93 shell
94 status
95 summary
96 tag
97 update
98 version
101 tg_cmd_will_setup() {
102 case "$1" in
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)
105 return 1
106 esac
107 return 0
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
121 done &&
122 has_no_tg_setup &&
123 cd .. && rm -rf r3
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
134 done &&
135 has_no_tg_setup &&
136 cd .. && rm -rf r4
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 &&
143 has_no_tg_setup &&
144 test_might_fail </dev/null tg $cmd &&
145 test_might_fail </dev/null tg $cmd --bogus-option-here &&
146 has_tg_setup &&
147 cd .. && rm -rf rt
150 done
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
158 done &&
159 has_no_tg_setup_bare &&
160 cd .. && rm -rf r5
163 test_done