better git based version numbering (hopefully sane)
[p5sagit/p5-mst-13.2.git] / make_patchnum.sh
1 #!/bin/sh
2
3 Existing=`cat .patchnum 2>/dev/null`
4 Existing_Sha1=`cat .sha1 2>/dev/null`
5 if [ -e ".patch" ]; then
6         Current=`awk '{print $4}' .patch`
7         Sha1=`awk '{print $3}' .patch`
8 elif [ -d ".git" ]; then
9         # we should do something better here
10         Current=`git describe`
11         Sha1=`git rev-parse HEAD`
12         Changed=`git diff-index --name-only HEAD`
13         [ -n "$Changed" ] && Current="$Current-with-uncommitted-changes"
14 fi
15
16 if [ "$Existing" != "$Current" -o "$Existing_Sha1" != "$Sha1" ]; then
17         echo "Updating .patchnum and .sha1"
18         echo -n $Current > .patchnum
19         echo -n $Sha1 > .sha1
20 else
21         echo "Reusing .patchnum and .sha1" 
22 fi