forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-branch
executable file
·43 lines (33 loc) · 1022 Bytes
/
deploy-branch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
function error_out {
echo -en '\e[0;31m'
echo "$1"
echo -en '\e[0m'
exit 1
}
status=$(git status --porcelain | grep -v '^??')
[ ! -z "$status" ] && error_out "Working directory or index not clean"
old_ref=$(git rev-list --max-count=1 HEAD)
branch=$1
branch_ref=$(git rev-list --max-count=1 "$branch")
[ $? -ne 0 ] && error_out "Unknown branch: $branch"
if [ "$old_ref" == "$branch_ref" ]; then
new_ref=master
else
ref_name=$(git describe --all --exact "$old_ref")
if [ $? -eq 0 ]; then
new_ref=$(echo "$ref_name" | perl -pe 's{^(heads|remotes)/}{}')
else
new_ref=$old_ref
fi
fi
[ -z "$branch" ] && error_out "You must specify a branch name to deploy"
git fetch -p
git rebase origin/master "$branch"
[ $? -ne 0 ] && error_out "Rebase onto origin/master failed"
git push . HEAD:master
git push origin master
[ $? -ne 0 ] && error_out "Push of master to origin/master failed"
git checkout "$new_ref"
git branch -D "$branch"
git push origin ":$branch"