aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-11 02:14:20 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-11 02:14:20 +0200
commit7f13a91e9c39dc70af12511443dceb6bf4dc80f4 (patch)
treeb5542788c8c8754f5960af43b1f2e6188304950b
parent0506f2d04314de141b94f1ab2c633462750e017a (diff)
downloadblogc-7f13a91e9c39dc70af12511443dceb6bf4dc80f4.tar.gz
blogc-7f13a91e9c39dc70af12511443dceb6bf4dc80f4.tar.bz2
blogc-7f13a91e9c39dc70af12511443dceb6bf4dc80f4.zip
git-receiver: added test for post-receive. fixed leak
-rw-r--r--Makefile.am1
-rw-r--r--src/blogc-git-receiver/pre-receive.c1
-rwxr-xr-xtests/blogc-git-receiver/check_pre_receive.sh148
3 files changed, 150 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 54c71bd..c4da494 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -321,6 +321,7 @@ endif
if BUILD_GIT_RECEIVER
dist_check_SCRIPTS += \
tests/blogc-git-receiver/check_post_receive.sh \
+ tests/blogc-git-receiver/check_pre_receive.sh \
$(NULL)
endif
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index 9bfc8a7..056ebf2 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -200,6 +200,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
rmdir_recursive(htdocs_sym);
cleanup:
+ free(master);
free(output_dir);
rmdir_recursive(dir);
free(repo_dir);
diff --git a/tests/blogc-git-receiver/check_pre_receive.sh b/tests/blogc-git-receiver/check_pre_receive.sh
new file mode 100755
index 0000000..dc2066f
--- /dev/null
+++ b/tests/blogc-git-receiver/check_pre_receive.sh
@@ -0,0 +1,148 @@
+#!/bin/bash
+
+set -xe -o pipefail
+
+export LC_ALL=C
+
+TEMP="$(mktemp -d)"
+[[ -n "${TEMP}" ]]
+
+trap_func() {
+ [[ -e "${TEMP}/output.txt" ]] && cat "${TEMP}/output.txt"
+ rm -rf "${TEMP}"
+}
+
+trap trap_func EXIT
+
+mkdir -p "${TEMP}/repos"
+git init --bare "${TEMP}/repos/foo.git" &> /dev/null
+
+SELF="${PWD}/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}" ${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}" ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt"
+grep "warning: no makefile found. skipping ..." "${TEMP}/output.txt" &> /dev/null
+
+cd "${TEMP}"
+rm -rf "${TEMP}/repos/foo.git"
+git init --bare "${TEMP}/repos/foo.git" &> /dev/null
+ln -s "${SELF}" "${TEMP}/repos/foo.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/foo.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}" ${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}"
+rm -rf "${TEMP}/repos/foo.git"
+git init --bare "${TEMP}/repos/foo.git" &> /dev/null
+ln -s "${SELF}" "${TEMP}/repos/foo.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/foo.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}" ${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}" ]]
+
+rm "${TEMP}/output.txt"