When an app directory (i.e. `/home/dokku/myapp`) is created before the app is pushed for the first time (which may occur if config files such as `ENV` are added before the initial push), then the app directory will not be initialized to a bare git repo nor will the pre-receive hook be installed because `plugins/git/commands` assumes that if `$APP_PATH` exists, then the directory must also be git initialized too. This fix checks for `$APP_PATH/refs` instead.
46 lines
1.2 KiB
Bash
Executable File
46 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|
|
|
case "$1" in
|
|
git-hook)
|
|
APP=$2
|
|
|
|
while read oldrev newrev refname
|
|
do
|
|
# Only run this script for the master branch. You can remove this
|
|
# if block if you wish to run it for others as well.
|
|
if [[ $refname = "refs/heads/master" ]] ; then
|
|
git archive $newrev | dokku receive $APP | sed -u "s/^/"$'\e[1G'"/"
|
|
else
|
|
echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to master."
|
|
echo $'\e[1G\e[K'"-----> for example, try 'git push <dokku> ${refname/refs\/heads\/}:master'"
|
|
fi
|
|
|
|
done
|
|
;;
|
|
|
|
git-*)
|
|
APP="$(echo $2 | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
|
|
APP_PATH=$DOKKU_ROOT/$APP
|
|
|
|
if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then
|
|
git init --bare $APP_PATH > /dev/null
|
|
PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive"
|
|
cat > $PRERECEIVE_HOOK <<EOF
|
|
#!/usr/bin/env bash
|
|
set -e; set -o pipefail;
|
|
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook $APP
|
|
EOF
|
|
chmod +x $PRERECEIVE_HOOK
|
|
fi
|
|
|
|
args=$@
|
|
git-shell -c "$args"
|
|
;;
|
|
|
|
help)
|
|
cat
|
|
;;
|
|
esac
|
|
|