Skip to content
Snippets Groups Projects
Commit 1e1f9009 authored by nimrod's avatar nimrod
Browse files

- A more realistic receiver script, added tests to verify said script.

parent cf9cd46b
No related branches found
No related tags found
No related merge requests found
#!/bin/sh #!/bin/sh
set -eu 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 mkdir -p /var/tmp/gitreceive
tar -xC /var/tmp/gitreceive -f - cd /var/tmp/gitreceive
echo "OK" 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.'
...@@ -59,9 +59,17 @@ ...@@ -59,9 +59,17 @@
args: args:
creates: /root/.ssh/known_hosts 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 - name: Add localhost as a git remote
blockinfile: blockinfile:
dest: /root/gitreceive/.git/config dest: /root/gitreceive-test/.git/config
block: | block: |
[remote "test"] [remote "test"]
url = git@localhost:test url = git@localhost:test
......
...@@ -6,10 +6,13 @@ testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') ...@@ -6,10 +6,13 @@ testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')
def test_gitreceive(Command, Sudo): def test_gitreceive(Command, Sudo):
with Sudo(): with Sudo():
Command('rm -rf /home/git/test /var/tmp/gitreceive') 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 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(): 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 second_push.rc == 0
assert 'Everything up-to-date' in second_push.stderr assert 'Everything up-to-date' in second_push.stderr
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment