aboutsummaryrefslogtreecommitdiffstats
path: root/tests/blogc-git-receiver/check_post_receive.sh.in
blob: 925ab31a74d2b2d3854fbfefdab349cdf358712d (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
#!@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

ln -s "${PWD}/blogc-git-receiver" "${TEMP}/repos/foo.git/hooks/post-receive"

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

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

EOF

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

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

HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt"
grep "warning: repository mirroring disabled" "${TEMP}/output.txt" &> /dev/null

git config --local remote.mirror.pushurl "${TEMP}/repos/bar.git"
HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt"
grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null

git config --local --unset remote.mirror.pushurl
git init --bare "${TEMP}/repos/bar2.git" &> /dev/null
git config --local remote.mirror.url "${TEMP}/repos/bar2.git"
HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt"
grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null

git config --local --unset remote.mirror.url
cat > "${TEMP}/blogc-git-receiver.ini" <<EOF
[repo:boo.git]
mirror = 123

[repo:foo.git]
mirror = ${TEMP}/repos/bar3.git

[repo:bar.git]
mirror = lol
EOF
git init --bare "${TEMP}/repos/bar3.git" &> /dev/null
HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt"
grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null

cat > "${TEMP}/blogc-git-receiver.ini" <<EOF
asd[repo:boo.git]
mirror = 123

[repo:foo.git]
mirror = ${TEMP}/repos/bar4.git

[repo:bar.git]
mirror = lol
EOF
git init --bare "${TEMP}/repos/bar4.git" &> /dev/null
HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt"
grep "warning: failed to parse configuration file " "${TEMP}/output.txt" &> /dev/null

cd ..
cat > "${TEMP}/blogc-git-receiver.ini" <<EOF
[repo:boo.git]
mirror = 123

[repo:foo.git]
mirror = ${TEMP}/repos/bar5.git

[repo:bar.git]
mirror = lol
EOF
git init --bare "${TEMP}/repos/bar5.git" &> /dev/null
HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./foo.git/hooks/post-receive 2>&1 | tee "${TEMP}/output.txt"
grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null

cd ..
cat > "${TEMP}/blogc-git-receiver.ini" <<EOF
[repo:boo.git]
mirror = 123

[repo:foo.git]
mirror = ${TEMP}/repos/bar6.git

[repo:bar.git]
mirror = lol
EOF
git init --bare "${TEMP}/repos/bar6.git" &> /dev/null
HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./repos/foo.git/hooks/post-receive 2>&1 | tee "${TEMP}/output.txt"
grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null

rm "${TEMP}/output.txt"