File: git-version-stamp.sh

package info (click to toggle)
awesome 4.3-8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,468 kB
  • sloc: ansic: 14,508; sh: 526; makefile: 46
file content (33 lines) | stat: -rwxr-xr-x 772 bytes parent folder | download | duplicates (5)
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
#!/bin/sh
#
# $1 file containing the last git-describe output
# $2 the file in which to update the version string
#
# TODO: proper error handling

die()
{
    echo "$0: WARNING: version stamp update failed: $1."
    #exit 1 # not important enough to stop the build.
    exit 0
}

STAMP=`cat "$1" 2> /dev/null`
if [ -z "$STAMP" ]; then
    die "Missing STAMP: $1"
fi

CURRENT=`git describe --dirty 2>/dev/null`
if [ -z "$CURRENT" ]; then
    die "git describe failed: $(git describe --dirty)."
fi

if [ "$STAMP" != "$CURRENT" ]
then
    echo "git version changed: $STAMP -> $CURRENT"
    sed -e s/$STAMP/$CURRENT/g "$2" 1> "$2.new" || die
    mv "$2.new" "$2"
    echo -n "$CURRENT" > "$1"
fi

# vim: filetype=sh:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80