Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
#!/usr/bin/env bash
set -euo pipefail
function error_out() {
echo -en '\e[0;31m'
echo "$1"
echo -en '\e[0m'
exit 1
}
[ -z "$(git status --porcelain --untracked-files=no)" ] || error_out "Working directory or index not clean"
old_ref=$(git rev-list --max-count=1 HEAD)
branch=${1-}
[ -z "$branch" ] && error_out "You must specify a branch name to deploy"
branch_ref=$(git rev-list --max-count=1 "$branch") || error_out "Unknown branch: $branch"
if [ "$old_ref" == "$branch_ref" ]; then
new_ref=main
else
if ref_name=$(git describe --all --exact "$old_ref"); then
new_ref=$(echo "$ref_name" | perl -pe 's{^(heads|remotes)/}{}')
else
new_ref=$old_ref
fi
fi
git fetch -p
git rebase origin/main "$branch" || error_out "Rebase onto origin/main failed"
git push . HEAD:main
git push origin main || error_out "Push of main to origin/main failed"
git checkout "$new_ref"
git branch -D "$branch"
git push origin ":$branch"