-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathcommit.sh
executable file
·165 lines (139 loc) · 3.59 KB
/
commit.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
DEV_BRANCH="astra-4"
usage()
{
cat <<EOF
Usage: ./commit.sh OPTIONS
Options:
--help
This message
--feature MESSAGE [FILES]
Commit to feature branch. Version is not changed
--hotfix MESSAGE [FILES]
Commit to '$DEV_BRANCH'. Dev version up
--major
Merge '$DEV_BRANCH' branch to 'master'
--minor
Merge '$DEV_BRANCH' branch to 'master'
--dev
Merge current branch to '$DEV_BRANCH'. Dev version up
Workflow:
1. Feature
# Start new branch
git checkout -b AS-X
# Commit changes into feature branch
./commit.sh --feature 'AS-X changes desciption' [files]
# Merge to dev
./commit.sh --dev
# Remove feature branch
git branch -d AS-X
# Remove remote branch if needed
git push origin :AS-X
2. Hotfix
# Commit changes into dev-branch directly
./commit.sh --hotfix 'AS-X changes desciption' [files]
3. Release
# After 'Feature' or after 'Hotfix'
./commit.sh --minor
EOF
exit 1
}
[ $# -lt 1 ] && usage
echo "$1" | grep -vq "^--" && usage
[ "$1" = "--help" -o "$1" = "-h" ] && usage
if [ ! -f "commit.sh" ] ; then
echo "Error: project is not found in the current direcory"
exit 2
fi
ASTRA_VERSION_MAJOR=`cat version.h | grep "ASTRA_VERSION_MAJOR " | cut -d ' ' -f 3`
ASTRA_VERSION_MINOR=`cat version.h | grep "ASTRA_VERSION_MINOR " | cut -d ' ' -f 3`
ASTRA_VERSION_DEV=`cat version.h | grep "ASTRA_VERSION_DEV " | cut -d ' ' -f 3`
BRANCH=`git branch | grep '^\*' | cut -d ' ' -f 2`
check_branch()
{
if [ "$BRANCH" != "$DEV_BRANCH" ] ; then
echo "$DEV_BRANCH is required."
echo "Current branch: $BRANCH"
exit 2
fi
}
version_up()
{
cat >version.h <<EOF
#ifndef _VERSION_H_
#define _VERSION_H_ 1
#define ASTRA_VERSION_MAJOR $ASTRA_VERSION_MAJOR
#define ASTRA_VERSION_MINOR $ASTRA_VERSION_MINOR
#define ASTRA_VERSION_DEV $ASTRA_VERSION_DEV
#endif /* _VERSION_H_ */
EOF
git add version.h
}
check_changes()
{
if ! git status | grep -q '^nothing' ; then
echo "Changes is not staged or not commited"
echo "Make commit or save it to stash"
exit 3
fi
}
release_version()
{
check_branch
check_changes
ASTRA_VERSION_DEV=0
version_up
git commit -m "version up" version.h
VERSION="v.$ASTRA_VERSION_MAJOR.$ASTRA_VERSION_MINOR"
git checkout master
git merge --no-ff $DEV_BRANCH -m "$VERSION merge with dev"
git tag "$VERSION"
git checkout $DEV_BRANCH
}
case "$1" in
"--feature")
shift
MSG="$1"
shift
if [ $# -ne 0 ] ; then
git commit -m "$MSG" $*
else
git commit -am "$MSG"
fi
;;
"--hotfix")
let ASTRA_VERSION_DEV=ASTRA_VERSION_DEV+1
version_up
shift
MSG="$1"
shift
if [ $# -ne 0 ] ; then
git commit -m "$MSG" $* version.h
else
git commit -am "$MSG"
fi
;;
"--major")
let ASTRA_VERSION_MAJOR=ASTRA_VERSION_MAJOR+1
ASTRA_VERSION_MINOR=0
release_version
;;
"--minor")
let ASTRA_VERSION_MINOR=ASTRA_VERSION_MINOR+1
release_version
;;
"--dev")
check_changes
git checkout $DEV_BRANCH
git merge --no-ff --no-commit $BRANCH
[ $? -ne 0 ] && exit
git reset HEAD version.h
git checkout -- version.h
let ASTRA_VERSION_DEV=ASTRA_VERSION_DEV+1
version_up
git commit -am "merge with $BRANCH"
;;
*)
usage
;;
esac