-
Notifications
You must be signed in to change notification settings - Fork 1
/
refrensh.deploy.example.sh
49 lines (44 loc) · 1.35 KB
/
refrensh.deploy.example.sh
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
44
45
46
47
48
49
# Local:
# https://stackoverflow.com/questions/21151178/shell-script-to-check-if-specified-git-branch-exists
# test if the branch is in the local repository.
# return 1 if the branch exists in the local, or 0 if not.
function is_in_local() {
local branch=${1}
local existed_in_local=$(git branch --list ${branch})
if [[ -z ${existed_in_local} ]]; then
echo 0
else
echo 1
fi
}
# Remote:
# Ref: https://stackoverflow.com/questions/8223906/how-to-check-if-remote-branch-exists-on-a-given-remote-repository
# test if the branch is in the remote repository.
# return 1 if its remote branch exists, or 0 if not.
function is_in_remote() {
local branch=${1}
local existed_in_remote=$(git ls-remote --heads origin ${branch})
if [[ -z ${existed_in_remote} ]]; then
echo 0
else
echo 1
fi
}
branch_name="${1}";
pid=prod-meta-polkadot;
if [ -z "$1" ]; then
git pull && yarn && pm2 restart $pid;
echo 'no branch given';
else
is_local=$(is_in_local $branch_name);
if [ "$is_local" = 1 ]; then
git checkout $branch_name && git pull && yarn && pm2 restart $pid;
echo "local branch ${1}";
else
is_remote=$(is_in_remote $branch_name);
if [ "$is_remote" = 1 ]; then
git pull && git checkout -t origin/$branch_name && yarn && pm2 restart $pid;
echo "remote branch ${1}";
fi
fi
fi