-
Notifications
You must be signed in to change notification settings - Fork 1
/
mk-version
executable file
·73 lines (60 loc) · 1.61 KB
/
mk-version
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
#!/bin/sh
# print vpnc version from file VERSION, appending the string printed
# by svnversion(1) if appropriate
in_git_repository ()
{
git rev-parse --is-inside-work-tree > /dev/null 2>&1
return $?
}
git_svn_version ()
{
# search for svn-remote defined in git configuration
svn_url_pattern=""
while read key value; do
svn_url_pattern="${svn_url_pattern}\\|${value}"
done << EOF
$(git config --get-regexp '^svn-remote\..*\.url$' 2>/dev/null)
EOF
# exit if no svn-remote defined
if [ -z "${svn_url_pattern}" ]; then
return
fi
# scan git-log for latest commit from any svn-remote above
set -- $(git log --first-parent -1 \
--grep="^git-svn-id: \(${svn_url_pattern#??}\)@" 2>/dev/null)
# check commit hash is 40 hex digits
svn_commit=$2
if [ ${#svn_commit} -ne 40 -o -z "${svn_commit##*[!0-9a-f]*}" ]; then
return
fi
# check svn version is numeric
shift $(($# - 2))
svn_ver=${1#*@}
if [ -z "${svn_ver}" -o -z "${svn_ver##*[!0-9]*}" ]; then
return
fi
if [ $(git rev-list HEAD...${svn_commit} | wc -l) -eq 0 ]; then
if [ `git status -s | grep -vc '^??'` -eq 0 ]; then
# no git commits and tree clean
echo "${svn_ver}"
return
fi
fi
# there are local git commits after latest svn commit or tree is dirty
echo "${svn_ver}M"
}
_version="`cat VERSION`"
if [ -d .svn ]; then
if which svnversion > /dev/null; then
_version="$_version-`svnversion`"
else
_version="$_version-`sed -n '/^dir$/{n;p;q;}' .svn/entries`"
fi
elif which git > /dev/null && in_git_repository; then
git_ext=$(git_svn_version)
if [ -n "${git_ext}" ]; then
_version="$_version-${git_ext}"
fi
fi
echo "$_version"
exit 0