2012-12-04 18:46:07 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function error_out {
|
|
|
|
echo -en '\e[0;31m'
|
2015-09-26 03:47:30 +02:00
|
|
|
echo "$1"
|
2012-12-04 18:46:07 +01:00
|
|
|
echo -en '\e[0m'
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
status=$(git status --porcelain | grep -v '^??')
|
2018-12-12 17:24:01 +01:00
|
|
|
[ -n "$status" ] && error_out "Working directory or index not clean"
|
2012-12-04 18:46:07 +01:00
|
|
|
|
|
|
|
old_ref=$(git rev-list --max-count=1 HEAD)
|
|
|
|
branch=$1
|
2018-08-03 02:14:48 +02:00
|
|
|
branch_ref=$(git rev-list --max-count=1 "$branch") || error_out "Unknown branch: $branch"
|
2012-12-04 18:46:07 +01:00
|
|
|
|
|
|
|
if [ "$old_ref" == "$branch_ref" ]; then
|
|
|
|
new_ref=master
|
|
|
|
else
|
2018-08-03 02:14:48 +02:00
|
|
|
if ref_name=$(git describe --all --exact "$old_ref"); then
|
2015-09-26 03:47:30 +02:00
|
|
|
new_ref=$(echo "$ref_name" | perl -pe 's{^(heads|remotes)/}{}')
|
2013-03-07 21:37:21 +01:00
|
|
|
else
|
|
|
|
new_ref=$old_ref
|
|
|
|
fi
|
2012-12-04 18:46:07 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -z "$branch" ] && error_out "You must specify a branch name to deploy"
|
|
|
|
|
|
|
|
git fetch -p
|
|
|
|
|
2018-08-03 02:14:48 +02:00
|
|
|
git rebase origin/master "$branch" || error_out "Rebase onto origin/master failed"
|
2012-12-04 18:46:07 +01:00
|
|
|
|
|
|
|
git push . HEAD:master
|
2018-08-03 02:14:48 +02:00
|
|
|
git push origin master || error_out "Push of master to origin/master failed"
|
2012-12-04 18:46:07 +01:00
|
|
|
|
2015-09-26 03:47:30 +02:00
|
|
|
git checkout "$new_ref"
|
|
|
|
git branch -D "$branch"
|
|
|
|
git push origin ":$branch"
|