2018-12-18 02:08:53 +01:00
|
|
|
#!/usr/bin/env bash
|
2012-12-04 18:46:07 +01:00
|
|
|
|
2020-10-15 04:55:57 +02:00
|
|
|
function error_out() {
|
2012-12-04 18:46:07 +01:00
|
|
|
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
|
2021-09-01 00:15:31 +02:00
|
|
|
new_ref=main
|
2012-12-04 18:46:07 +01:00
|
|
|
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
|
|
|
|
|
2021-09-01 00:15:31 +02:00
|
|
|
git rebase origin/main "$branch" || error_out "Rebase onto origin/main failed"
|
2012-12-04 18:46:07 +01:00
|
|
|
|
2021-09-01 00:15:31 +02:00
|
|
|
git push . HEAD:main
|
|
|
|
git push origin main || error_out "Push of main to origin/main 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"
|