-
Notifications
You must be signed in to change notification settings - Fork 5
/
masterToBranch-helper.sh
executable file
·131 lines (106 loc) · 3.22 KB
/
masterToBranch-helper.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
ORIGIN_REPO_URL=https://[email protected]/startx1/containers.git
# check if git is installed
function checkGitInstalled {
retn=$(git --version | grep version)
if [ $? != 0 ]; then
echo "git is not installed."
echo "Install git client first"
exit 1;
fi
}
# check if is in git directory
function checkDirectoryIsGit {
retn=$(git status &>/dev/null)
if [ $? != "0" ]; then
echo "your are not in a git repository"
echo "please run 'git clone $ORIGIN_REPO_URL docker-images && cd docker-images' first"
exit 2;
fi
}
# check if git repo is the good one
function checkGitRepoIsOrigin {
retn=$(git remote show origin | grep 'Fetch URL: ' | sed 's/ *//g' | cut -c 10-)
if [ "$retn" != "$ORIGIN_REPO_URL" ]; then
echo "your are not in the $ORIGIN_REPO_URL repo"
echo "please run 'mv ..' first"
exit 3;
fi
}
# check if git branch is master
function checkGitBranchIsMaster {
git branch | grep '* master' &> /tmp/aaa
if [[ $(cat /tmp/aaa) != '* master' ]]; then
echo "your are not in the master branch"
echo "please run 'git checkout master' first"
git checkout master
git branch | grep '* master' &> /tmp/aaa
if [[ $(cat /tmp/aaa) != '* master' ]]; then
echo "your are not in the master branch"
echo "please run 'git checkout master' first"
exit 4;
fi
fi
rm -f /tmp/aaa
}
# check if git branch has no file to commit
function checkGitBranchIsCommited {
retn=$(git status -s | wc -l)
if [ $retn -gt 0 ]; then
echo "There is some file waiting for commit"
echo "please run 'git commit' first"
git status
exit 5;
fi
}
# check if git branch has no file to commit
function checkReadyForRun {
checkGitInstalled
checkDirectoryIsGit
checkGitRepoIsOrigin
checkGitBranchIsMaster
checkGitBranchIsCommited
}
# merge master into a target branch
function exectuteMerge {
if [ $2 == "" ]; then
echo "You must give a tag name"
echo "please run 'masterToBranch-helper.sh run fc34' first"
exit 5;
fi
git checkout $2 && git merge master && git checkout master
}
# merge master into a target branch
function exectutePush {
type=$2
if [ $2 == "" ]; then
type="all"
fi
if [ $type == "all" ]; then
git checkout master && git push origin master fc36 fc35 fc34 fc33 fc32 fc31 fc30 ubi8 alpine rocky8 alma8 centos8 centos7 centos6
else
git checkout master && git push origin $2
fi
}
# Display general usage
function menuUsage {
cat <<EOF
merge master to image tag helper
Usage:
masterToBranch-helper.sh [command]
- General commands:
simulate ≤name> simulate a merge to the target branch
run ≤name> execute a merge to the target branch
push ≤name> push one branch
push all push all branch
usage this message
EOF
}
checkReadyForRun
# Dispatch input arguments
case $1 in
simulate) simulateMerge $@ ;;
run|exec|merge) exectuteMerge $@ ;;
push) exectutePush $@ ;;
*) menuUsage $@ ;;
esac