forked from apaka/win-sshfs
-
Notifications
You must be signed in to change notification settings - Fork 125
/
version.hook.sh
40 lines (31 loc) · 1.45 KB
/
version.hook.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
#!/bin/bash
#Git Post Merge Hook
#---------------------
#Gets the latest tag info from the git repo and updates the AssemblyInfo.cs file with it.
#This file needs to be place in the .git/hooks/ folder and only works when a git pull is
#made which contains changes in the remote repo.
PRODUCT="WinSshFS Foreveryone"
#get the latest tag info. The 'always' flag will give you a shortened SHA1 if no tag exists.
tag=$(git describe --tags --long)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
#tag="A.B.C.D-X-hash"
echo $tag
AI="Sshfs/Sshfs/Properties/AssemblyInfo.cs"
#If no tag has been added only the sha1 will be returned
if [[ $tag=="*.*" ]]
then
IFS='-' read -ra PARTS <<< "$tag"
IFS='.' read -ra TAG <<< "${PARTS[0]}"
#echo "${TAG[2]}"
#echo "${TAG[3]}"
IFS='-' read -ra COMMITS <<< "${PARTS[1]}"
#echo "${COMMITS[0]}"
#This will be the version in the format <major>.<minor>.<build number> (.<revision> remove revision, amend of version inside will be ok with this)
version="${TAG[0]}"."${TAG[1]}"."${TAG[2]}"."${COMMITS[0]}"
echo $version
#Update the AssemblyVersion and AssemblyFileVersion attribute with the 'version'
sed -i.bak "s/\AssemblyVersion(\".*\")/AssemblyVersion(\"$version\")/g" $AI 2>/dev/null
sed -i.bak "s/\AssemblyFileVersion(\".*\")/AssemblyFileVersion(\"$version\")/g" $AI 2>/dev/null
sed -i.bak "s/AssemblyProduct(\".*\")/AssemblyProduct(\"$PRODUCT $version-${BRANCH}\")/g" $AI 2>/dev/null
#cat $AI
fi