-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathnew_hotfix_branch.sh
executable file
·94 lines (82 loc) · 1.86 KB
/
new_hotfix_branch.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
#!/bin/bash
function yellow (){
echo "$(tput setaf 3)$1$(tput setaf 7)"
}
function green (){
echo "$(tput setaf 2)$1$(tput setaf 7)"
}
function cyan (){
echo "$(tput setaf 6)$1$(tput setaf 7)"
}
function printUsage(){
echo ""
yellow "Create Hotfix Branch."
echo ""
echo "Usage: $(basename $0) [--repo|-r repopath] [--tag|-t tagversion]"
echo ""
cyan "Options:"
green " -r --repo STRING Repo to create the new branch"
green " -t --tag STRING Tag to create the branch from"
echo ""
}
## Check if the repo status is clean.
function check_repo_clean() {
GIT_STATUS=$(git status --short)
if [ -n "$GIT_STATUS" ]; then
yellow "Repository is not clean:"
yellow "$GIT_STATUS"
exit
fi
}
## At least one parameter is required.
if [ -z "$1" ]; then
printUsage
exit 1
fi
while [[ $# -gt 0 ]]; do
key="$1"
value="$2"
case $key in
-h | --help)
printUsage
exit 0
;;
-r | --repo)
REPO_DIR="$value"
shift # past argument
shift # past value
;;
-t | --tag)
TAG_VERSION="$value"
shift # past argument
shift # past value
;;
*) # unknown option
echo "Unknown option $key"
printUsage
exit 1
;;
esac
done
if [ -z "$REPO_DIR" ]; then
printUsage
exit 1
fi
if [ -z "$TAG_VERSION" ]; then
printUsage
exit 1
fi
cd "$REPO_DIR" || exit 2
if [[ "$TAG_VERSION" == "v"* ]]; then
git checkout "$TAG_VERSION"
RELEASE_BRANCH="release-${TAG_VERSION//v}.x"
git checkout -b "$RELEASE_BRANCH"
POM_VERSION="${TAG_VERSION//v}.1-SNAPSHOT"
mvn versions:set -DnewVersion="$POM_VERSION" -DgenerateBackupPoms=false
git commit -am "Prepare new development branch $RELEASE_BRANCH"
git push --set-upstream origin "$RELEASE_BRANCH"
else
yellow "[$TAG_VERSION] The tag name must start with v"
exit
fi
yellow "The new dependency version is $NEW_VERSION"