forked from pbatard/rufus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_pre-commit.sh
46 lines (40 loc) · 1.65 KB
/
_pre-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
#!/bin/sh
#
# Bumps the micro version according to the number of commits on this branch
#
# To have git run this script on commit, create a "pre-commit" text file in
# .git/hooks/ with the following content:
# #!/bin/sh
# if [ -x ./_pre-commit.sh ]; then
# source ./_pre-commit.sh
# fi
type -P sed &>/dev/null || { echo "sed command not found. Aborting." >&2; exit 1; }
type -P git &>/dev/null || { echo "git command not found. Aborting." >&2; exit 1; }
VER=`git log --oneline | wc -l`
# adjust so that we match the github commit count
TAGVER=`expr $VER + 1`
# there may be a better way to prevent improper micro on amend. For now the detection
# of a .amend file in the current directory will do
if [ -f ./.amend ]; then
TAGVER=`expr $TAGVER - 1`
git tag -d "b$TAGVER"
rm ./.amend;
fi
echo "setting micro to $TAGVER"
echo $TAGVER > .tag
cat > cmd.sed <<\_EOF
s/^[ \t]*FILEVERSION[ \t]*\(.*\),\(.*\),.*,\(.*\)/ FILEVERSION \1,\2,@@TAGVER@@,\3/
s/^[ \t]*PRODUCTVERSION[ \t]*\(.*\),\(.*\),.*,\(.*\)/ PRODUCTVERSION \1,\2,@@TAGVER@@,\3/
s/^\([ \t]*\)VALUE[ \t]*"FileVersion",[ \t]*"\(.*\)\..*"/\1VALUE "FileVersion", "\2.@@TAGVER@@"/
s/^\([ \t]*\)VALUE[ \t]*"ProductVersion",[ \t]*"\(.*\)\..*"/\1VALUE "ProductVersion", "\2.@@TAGVER@@"/
s/^\(.*\)"Rufus \(.*\)\..*"\(.*\)/\1"Rufus \2.@@TAGVER@@"\3/
_EOF
# First run sed to substitute our variable in the sed command file
sed -i -e "s/@@TAGVER@@/$TAGVER/g" cmd.sed
# Run sed to update the nano version
sed -i -f cmd.sed src/rufus.rc
# MinGW's sed has the bad habit of eating CRLFs - make sure we keep 'em
sed -i 's/$/\r/' src/rufus.rc
# NB: we need to run git add else the modified files may be ignored
git add src/rufus.rc
rm cmd.sed