-
Notifications
You must be signed in to change notification settings - Fork 17
/
gitflow-functions
194 lines (164 loc) · 4.22 KB
/
gitflow-functions
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Version variables
AVH_MAJOR=""
AVH_MINOR=""
AVH_PATCH_LEVEL=""
AVH_PRE_RELEASE=""
AVH_VERSION=""
# Colors
RED=`printf '\033[1;31m'`
GREEN=`printf '\033[1;32m'`
WHITE=`printf '\033[1;37m'`
GREY=`printf '\033[1;36m'`
# Icons
CHECK=`printf ${GREEN}'✔'${WHITE}`
CROSS=`printf ${RED}'✘'${WHITE}`
# Modules directory
HOOKS_MODULES_DIR="$HOOKS_DIR"/modules
REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ ! -f "$REPO_DIR"/.git/hooks_config ]; then
echo "\n${CROSS}${RED} Missing file "$REPO_DIR"/.git/hooks_config"
exit 127
fi
. "$REPO_DIR"/.git/hooks_config
type _update_version >/dev/null 2>&1;
if [ $? -eq 127 ]; then
echo "\n${CROSS}${RED} Missing function _update_version!\nThis function should be declared in "$REPO_DIR"/.git/hooks_config"
exit 127
fi
gitflow_update_version() {
if [ -n "$2" ]; then
MSG="$2"
else
MSG="Version bump $1"
fi
_update_version $1
git commit -a -m "$MSG"
}
gitflow_set_major_minor() {
local TEMP_VERSION=$1
AVH_MAJOR=$(echo "$TEMP_VERSION" | cut -f1 -d".")
if $(gitflow_contains "$TEMP_VERSION" "."); then
TEMP_VERSION=$(echo ${TEMP_VERSION#*.})
AVH_MINOR=$(echo "$TEMP_VERSION" | cut -f1 -d"."|cut -f1 -d"-")
if [ -z $AVH_MINOR ]; then
AVH_MINOR=0
AVH_PATCH_LEVEL=0
else
if $(gitflow_contains "$TEMP_VERSION" "."); then
TEMP_VERSION=$(echo ${TEMP_VERSION#*.})
AVH_PATCH_LEVEL=$(echo "$TEMP_VERSION" | cut -f1 -d"."|cut -f1 -d"-")
[ -z $AVH_PATCH_LEVEL ] && AVH_PATCH_LEVEL=0
else
AVH_PATCH_LEVEL=0
fi
fi
else
AVH_MINOR=0
AVH_PATCH_LEVEL=0
fi
}
gitflow_build_version() {
AVH_VERSION=$AVH_MAJOR.$AVH_MINOR.$AVH_PATCH_LEVEL
[ -n AVH_PRE_RELEASE ] && AVH_VERSION=$AVH_VERSION$AVH_PRE_RELEASE
}
#
# Set the pre-release, it counts all commits but not the one in master
#
gitflow_set_dev_release() {
AVH_PRE_RELEASE=-dev.$(git rev-list --count HEAD ^"$MASTER_BRANCH")
}
#
# Set the rc-release, it counts all commits but not the one in master
#
gitflow_set_rc_release() {
local RC_LEVEL=$(echo "$1" | cut -f2 -d"-"|cut -f2 -d".")
RC_LEVEL=$(($RC_LEVEL+1))
AVH_PRE_RELEASE=-rc.$RC_LEVEL
}
gitflow_get_current_version() {
CURRENT_VERSION=$(grep -m1 "GITFLOW_VERSION=" $ROOTDIR/git-flow-version | cut -f2 -d"=")
echo "$CURRENT_VERSION"
}
#
# Create an up to date AUTHORS file
#
gitflow_update_authors() {
ROOTDIR=$(git rev-parse --show-toplevel)
AUTHORS=$(mktemp --suffix=.gitflow)
# Create an up to date AUTHORS file
echo "git-flow AVH Authors
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
(Changes.mdown) and logs, available at
http://github.com/petervanderdoes/gitflow.
" > $AUTHORS
git shortlog -ns --no-merges | cut -f2 >> $AUTHORS
echo "
Portions of the project are derived from other open source works are clearly
marked.
This file is auto generated, any changes will be lost." >> $AUTHORS
# Check if the new file is different
# If it's not there is no need to copy it and commit
diff $AUTHORS $ROOTDIR/AUTHORS > /dev/null 2>&1
DIFF=$?
if [ $DIFF -ne 0 ]; then
cp $AUTHORS $ROOTDIR/AUTHORS
git commit AUTHORS -m "Update of the contributers."
fi
# Clean up
rm $AUTHORS
}
#
# String contains function
# $1 haystack
# $2 Needle
#
gitflow_contains() {
local return
case $1 in
*$2*)
return=0
;;
*)
return=1
;;
esac
return $return
}
gitflow_fail() {
echo "\t"${CROSS} ${GREY}$1${WHITE}
}
gitflow_ok() {
echo "\t"${CHECK} ${GREY}$1${WHITE}
}
h1() {
echo "\n${WHITE}$1 ...\n"
}
# Function to get a list of files that will be committed by extension
# you can for example do "$(commit_files js css)" to get a list of js and css files that will be committed
gitflow_commit_files() {
if [ $# -eq 0 ] ; then
echo $(git diff-index --name-only --diff-filter=ACM --cached HEAD --)
exit 0
fi
extensions=''
for extension in "$@"
do
extensions="${extensions}(${extension})|"
done
regex="\.(${extensions%?})$"
echo $(git diff-index --name-only --diff-filter=ACM --cached HEAD -- | grep -P "$regex")
}
gitflow_count_commit_files() {
echo $(gitflow_commit_files $@) | wc -w | tr -d ' '
}
gitflow_validInt() {
local _return
[ -n "$1" ] || return 1
_int="$1"
case "${_int}" in
*[!0-9]*) _return=1 ;;
*) _return=0 ;;
esac
return $_return
}