Commit 1e1f9009 authored by nimrod's avatar nimrod
Browse files

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

parent cf9cd46b
Loading
Loading
Loading
Loading
+36 −2
Original line number Diff line number Diff line
#!/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.'
+9 −1
Original line number Diff line number Diff line
@@ -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
+6 −3
Original line number Diff line number Diff line
@@ -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