-
Notifications
You must be signed in to change notification settings - Fork 148
/
precommit-hook
35 lines (29 loc) · 1.34 KB
/
precommit-hook
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
# Configuration
# -------------
# The Manifest path is relative to THIS script.
# If you copy-and-paste this into your pre-commit hook
# and your AndroidManifest.xml is in the root of your repo
# then the path would be:
# MANIFEST="../../AndroidManifest.xml"
# If this is in the same directory then it's just:
MANIFEST="../../AndroidManifest.xml"
# Script DO NOT MODIFY (unless you want to)
declare -x SCRIPTPATH="${0}"
FULLPATH=${SCRIPTPATH%/*}/$MANIFEST
if [ -f $FULLPATH ]
then
LINE=$(grep -o ${FULLPATH} -e 'android:versionCode="[0-9]*"');
declare -a LINE;
LINE=(`echo $LINE | tr "\"" " "`);
VERSION=(${LINE[1]});
INCREMENTED=$(($VERSION+1))
sed "s/android:versionCode=\"[0-9]*\"/android:versionCode=\"${INCREMENTED}\"/" $FULLPATH > $FULLPATH.tmp && mv $FULLPATH.tmp $FULLPATH
echo "Updated android:versionCode to ${INCREMENTED} in ${FULLPATH}";
LINE_VERSION_NAME=$(grep -o ${FULLPATH} -e 'android:versionName="2.0"');
declare -a LINE_VERSION_NAME;
LINE_VERSION_NAME=(`echo $LINE_VERSION_NAME | tr "\"" " "`);
VERSION_NAME=(${LINE_VERSION_NAME[1]});
VERSION_INCREMENTED=$(($VERSION_NAME+1))
sed "s/android:versionName=\"[0-9]*\"/android:versionName=\"${VERSION_INCREMENTED}\"/" $FULLPATH > $FULLPATH.tmp && mv $FULLPATH.tmp $FULLPATH
echo "Updated android:versionName to ${VERSION_INCREMENTED} in ${FULLPATH}";
fi;