aboutsummaryrefslogtreecommitdiffstats
path: root/tests/blogc-git-receiver/check_pre_receive.sh.in
blob: e9181eb1c94d4da6b61930cefec37482e77a1cae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!@BASH@

set -xe -o pipefail

export LC_ALL=C

TEMP="$(mktemp -d)"
[[ -n "${TEMP}" ]]

trap_func() {
    [[ -e "${TEMP}/output.txt" ]] && cat "${TEMP}/output.txt"
    [[ -n "${TEMP}" ]] && rm -rf "${TEMP}"
}

trap trap_func EXIT

mkdir -p "${TEMP}/repos"
git init --bare "${TEMP}/repos/foo.git" &> /dev/null

SELF="@abs_top_builddir@/blogc-git-receiver"

ln -s "${SELF}" "${TEMP}/repos/foo.git/hooks/pre-receive"

cat > "${TEMP}/payload.txt" <<EOF
0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/foo
0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/bar
EOF

cd "${TEMP}/repos/foo.git"

SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt"
grep "warning: no reference to master branch found. nothing to deploy." "${TEMP}/output.txt" &> /dev/null

cat > "${TEMP}/tmp.txt" <<EOF
blob
mark :1
data 63
all:
	mkdir -p \$(OUTPUT_DIR)
	echo lol > \$(OUTPUT_DIR)/foo.txt

reset refs/heads/master
commit refs/heads/master
mark :2
author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476139736 +0200
committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476139736 +0200
data 11
testing...
M 100644 :1 Makefil

EOF

git fast-import < "${TEMP}/tmp.txt" &> /dev/null

cat > "${TEMP}/payload.txt" <<EOF
0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/foo
0000000000000000000000000000000000000000 $(git rev-parse HEAD) refs/heads/master
0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/bar
EOF

SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt"
grep "warning: no blogcfile or Makefile found. skipping ..." "${TEMP}/output.txt" &> /dev/null

cd "${TEMP}"
git init --bare "${TEMP}/repos/foo2.git" &> /dev/null
ln -s "${SELF}" "${TEMP}/repos/foo2.git/hooks/pre-receive"

cat > "${TEMP}/tmp.txt" <<EOF
blob
mark :1
data 63
all:
	mkdir -p \$(OUTPUT_DIR)
	echo lol > \$(OUTPUT_DIR)/foo.txt

reset refs/heads/master
commit refs/heads/master
mark :2
author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476139736 +0200
committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476139736 +0200
data 11
testing...
M 100644 :1 Makefile

EOF

cd "${TEMP}/repos/foo2.git"
git fast-import < "${TEMP}/tmp.txt" &> /dev/null

cat > "${TEMP}/payload.txt" <<EOF
0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/foo
0000000000000000000000000000000000000000 $(git rev-parse HEAD) refs/heads/master
0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/bar
EOF

SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt"
grep "echo lol" "${TEMP}/output.txt" &> /dev/null

[[ -h htdocs ]]
[[ "$(cat htdocs/foo.txt)" == "lol" ]]

DEST="$(readlink htdocs)"
[[ -e "${DEST}" ]]

cd "${TEMP}"
git init --bare "${TEMP}/repos/foo3.git" &> /dev/null
ln -s "${SELF}" "${TEMP}/repos/foo3.git/hooks/pre-receive"

cat > "${TEMP}/tmp.txt" <<EOF
blob
mark :1
data 64
all:
	mkdir -p \$(OUTPUT_DIR)
	echo lol > \$(OUTPUT_DIR)/foo.txt


commit refs/heads/master
mark :2
author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476142917 +0200
committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476142917 +0200
data 12
testing2...
M 100644 :1 Makefile

EOF

cd "${TEMP}/repos/foo3.git"
ln -s "${DEST}" htdocs
git fast-import < "${TEMP}/tmp.txt" &> /dev/null

cat > "${TEMP}/payload.txt" <<EOF
0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/foo
0000000000000000000000000000000000000000 $(git rev-parse HEAD) refs/heads/master
0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/bar
EOF

SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt"
grep "echo lol" "${TEMP}/output.txt" &> /dev/null

[[ -h htdocs ]]
[[ "$(cat htdocs/foo.txt)" == "lol" ]]
[[ "${DEST}" != "$(readlink htdocs)" ]]
[[ ! -e "${DEST}" ]]

DEST="$(readlink htdocs)"
HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/pre-receive 2>&1 | tee "${TEMP}/output.txt"

[[ -h htdocs ]]
[[ "$(cat htdocs/foo.txt)" == "lol" ]]
[[ "${DEST}" != "$(readlink htdocs)" ]]
[[ ! -e "${DEST}" ]]

cd ..

DEST="$(readlink foo3.git/htdocs)"
HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./foo3.git/hooks/pre-receive 2>&1 | tee "${TEMP}/output.txt"

[[ -h foo3.git/htdocs ]]
[[ "$(cat foo3.git/htdocs/foo.txt)" == "lol" ]]
[[ "${DEST}" != "$(readlink foo3.git/htdocs)" ]]
[[ ! -e "${DEST}" ]]

cd ..

DEST="$(readlink repos/foo3.git/htdocs)"
HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./repos/foo3.git/hooks/pre-receive 2>&1 | tee "${TEMP}/output.txt"

[[ -h repos/foo3.git/htdocs ]]
[[ "$(cat repos/foo3.git/htdocs/foo.txt)" == "lol" ]]
[[ "${DEST}" != "$(readlink repos/foo3.git/htdocs)" ]]
[[ ! -e "${DEST}" ]]

if [[ "x@MAKE_@" == "xenabled" ]]; then
    cd "${TEMP}"
    git init --bare "${TEMP}/repos/foo4.git" &> /dev/null
    ln -s "${SELF}" "${TEMP}/repos/foo4.git/hooks/pre-receive"

    cat > "${TEMP}/tmp.txt" <<EOF
blob
mark :1
data 0

reset refs/heads/master
commit refs/heads/master
mark :2
author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1483558736 +0100
committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1483558736 +0100
data 12
testing3...
M 100644 :1 blogcfile

EOF

    cd "${TEMP}/repos/foo4.git"
    git fast-import < "${TEMP}/tmp.txt" &> /dev/null

    cat > "${TEMP}/payload.txt" <<EOF
0000000000000000000000000000000000000000 $(git rev-parse HEAD) refs/heads/master
EOF

    SHELL="${SELF}" HOME="${TEMP}" PATH="@abs_top_builddir@:${PATH}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" || true
    grep "blogc-make: error: settings: " "${TEMP}/output.txt" &> /dev/null
fi

rm "${TEMP}/output.txt"