-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
101 lines (93 loc) · 3.82 KB
/
update.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
projectRootDir=`pwd`
masterSrcBranchName="master"
devSrcBranchName="dev_xxx"
masterConfigBranchName="master"
devConfigBranchName="dev_xxx"
originSrcBranchName=""
update()
{
local originBranchName=${1}
local masterBranchName=${2}
local devBranchName=${3}
local bCleanOriginBranch=0
local bCleanDevBranch=0
if [ $originBranchName == $devBranchName ]
then
bCleanDevBranch=0
if [[ -n $(git diff --stat) ]] ## 判断当前仓库干不干净
then
bCleanDevBranch=0
else
bCleanDevBranch=1
fi
if [[ $bCleanDevBranch == 0 ]]
then
echo "-------------------- stash save $devBranchName --------------------"
git stash
echo "-------------------- end --------------------"
fi
echo "-------------------- switch to $masterBranchName --------------------"
git switch $masterBranchName
echo "-------------------- end --------------------"
echo "-------------------- update $masterBranchName --------------------"
git pull
echo "-------------------- end --------------------"
echo "-------------------- switch to $devBranchName --------------------"
git switch $devBranchName
echo "-------------------- end --------------------"
echo "-------------------- merge $masterBranchName to $devBranchName --------------------"
git merge $masterBranchName
echo "-------------------- end --------------------"
if [[ $bCleanDevBranch == 0 ]]
then
echo "-------------------- stash pop $devBranchName --------------------"
git stash pop
echo "-------------------- end --------------------"
fi
else
bCleanOriginBranch=0
if [[ -n $(git diff --stat) ]]
then
bCleanOriginBranch=0
else
bCleanOriginBranch=1
fi
if [[ $bCleanOriginBranch == 0 ]]
then
echo "-------------------- stash save $originBranchName --------------------"
git stash
echo "-------------------- end --------------------"
fi
echo "-------------------- switch to $masterBranchName --------------------"
git switch $masterBranchName
echo "-------------------- end --------------------"
echo "-------------------- update $masterBranchName --------------------"
git pull
echo "-------------------- end --------------------"
echo "-------------------- switch to $devBranchName --------------------"
git switch $devBranchName
echo "-------------------- end --------------------"
echo "-------------------- merge $masterBranchName to $devBranchName --------------------"
git merge $masterBranchName
echo "-------------------- end --------------------"
echo "-------------------- switch to $originBranchName --------------------"
git switch $originBranchName
echo "-------------------- end --------------------"
if [[ $bCleanOriginBranch == 0 ]]
then
echo "-------------------- stash pop $originBranchName --------------------"
git stash pop
echo "-------------------- end --------------------"
fi
fi
}
echo -e "\033[36m---------- update `pwd` ----------\033[0m"
originSrcBranchName=`git rev-parse --abbrev-ref HEAD`
update $originSrcBranchName $masterSrcBranchName $devSrcBranchName
echo -e "\033[36m-------------------- end --------------------\033[0m"
cd $projectRootDir/common
echo -e "\033[36m---------- update `pwd` ----------\033[0m"
originSrcBranchName=`git rev-parse --abbrev-ref HEAD`
update $originSrcBranchName $masterConfigBranchName $devConfigBranchName
echo -e "\033[36m-------------------- end --------------------\033[0m"