diff --git a/tests/files/receiver.sh b/tests/files/receiver.sh index efff13d9ad3692d863f81cd7aefd0261afc41f5f..5f62f46b5c801e73b74961589c50f5c29cecefcb 100644 --- a/tests/files/receiver.sh +++ b/tests/files/receiver.sh @@ -1,5 +1,39 @@ #!/bin/sh set -eu + +# This part was copied verbatim from +# https://github.com/progrium/gitreceive/wiki/TipsAndTricks +fetch_submodules () { + # We reinitialize .git to avoid conflicts + rm -fr .git + # GIT_DIR is previously set by gitreceive to ".", we want it back to default + # for this + unset GIT_DIR + git init . + + # We read the submodules from .gitmodules + git config -f .gitmodules --get-regexp '^submodule\..*\.path$' | + while read path_key path + do + rm -fr $path + url_key=`echo $path_key | sed 's/\.path/.url/'` + url=`git config -f .gitmodules --get "$url_key"` + git submodule add $url $path + done +} + mkdir -p /var/tmp/gitreceive -tar -xC /var/tmp/gitreceive -f - -echo "OK" +cd /var/tmp/gitreceive +echo '----> Unpacking ...' +tar -xf - +if [ -f .gitmodules ] +then + echo '----> Fetching submodules ...' + fetch_submodules +fi +if [ -f receiver ] && [ -x receiver ] +then + echo '----> Running receiver ...' + ./receiver +fi +echo '----> OK.' diff --git a/tests/playbook.yml b/tests/playbook.yml index 72e6f28c68da5807fb0d1ef6ebcd3e53a93417a7..eac28b9d7b51db4ebf6ca8109e51ae67149d8726 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -59,9 +59,17 @@ args: creates: /root/.ssh/known_hosts + - name: Clone gitreceive test repo + git: + dest: /root/gitreceive-test + force: yes + update: yes + repo: https://www.shore.co.il/git/gitreceive-test + version: master + - name: Add localhost as a git remote blockinfile: - dest: /root/gitreceive/.git/config + dest: /root/gitreceive-test/.git/config block: | [remote "test"] url = git@localhost:test diff --git a/tests/test_gitreceive.py b/tests/test_gitreceive.py index 85cc5ea30363d8ae9248088202fe8b25cf985d85..87860860c6994cee7b1cdb21900f9b3db31ed947 100644 --- a/tests/test_gitreceive.py +++ b/tests/test_gitreceive.py @@ -6,10 +6,13 @@ testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') def test_gitreceive(Command, Sudo): with Sudo(): Command('rm -rf /home/git/test /var/tmp/gitreceive') - push = Command('git -C /root/gitreceive push test master') + push = Command('git -C /root/gitreceive-test push test master') assert push.rc == 0 - assert 'OK' in push.stderr + for message in ['----> Unpacking ...', '----> Fetching submodules ...', + '----> Running receiver ...', 'Dummy receiver script', + '----> OK.']: + assert message in push.stderr with Sudo(): - second_push = Command('git -C /root/gitreceive push test master') + second_push = Command('git -C /root/gitreceive-test push test master') assert second_push.rc == 0 assert 'Everything up-to-date' in second_push.stderr