wujku
9/11/2017 - 1:00 PM

gitlab_deployment_configuration.sh

#!/usr/bin/env bash

# Usage: repository=repository_name.git worktree=/home/user/domains/domain.name gitlab_deployment_configuration.sh 

if [ -z ${repository+x} ]; then repository=gitlab.git; fi
if [ -z ${worktree+x} ]; then worktree=/home/ubuntu/domains/domain.name; fi

# create git --bare repository
git init --bare ${repository}

cd ${repository}

# create post-receive hook
bash -c "cat >> hooks/post-receive" <<'EOL'
#!/bin/sh

read OLDREV NEWREV REFNAME
WORKTREE=`git config core.worktree`

# checkout current commit

echo "git checkout develop --force"
git checkout develop --force
EOL

# add execute permission
chmod +x hooks/post-receive

git config core.worktree ${worktree}
git config core.bare false
git config receive.denyCurrentBranch ignore