blob: cbed7daf5b618f1c80c398c9e267a58a1253444f [file] [log] [blame]
Daniel Dunbare40eb092010-01-21 16:09:59 +00001#!/bin/sh
2
Daniel Dunbarf63623f2010-01-22 18:14:21 +00003usage() {
Daniel Dunbar1619beb2010-09-29 17:57:01 +00004 echo "usage: $0 <source root>"
5 echo " Prints the source control revision of the given source directory,"
6 echo " the exact format of the revision string depends on the source "
7 echo " control system. If the source control system isn't known, the output"
8 echo " is empty and the exit code is 1."
9 exit 1
Daniel Dunbare40eb092010-01-21 16:09:59 +000010}
11
12if [ $# != 1 ] || [ ! -d $1 ]; then
13 usage;
14fi
15
16cd $1
17if [ -d .svn ]; then
Daniel Dunbar6a2e9122010-09-29 19:30:17 +000018 svnversion | sed -e "s#\([0-9]*\)[A-Z]*#\1#"
Daniel Dunbare40eb092010-01-21 16:09:59 +000019elif [ -d .git/svn ]; then
Daniel Dunbar1619beb2010-09-29 17:57:01 +000020 git svn info | grep 'Revision:' | cut -d: -f2-
Daniel Dunbare40eb092010-01-21 16:09:59 +000021elif [ -d .git ]; then
Daniel Dunbar1619beb2010-09-29 17:57:01 +000022 git log -1 --pretty=format:%H
Daniel Dunbare40eb092010-01-21 16:09:59 +000023else
Daniel Dunbar1619beb2010-09-29 17:57:01 +000024 exit 1;
Daniel Dunbare40eb092010-01-21 16:09:59 +000025fi
26
27exit 0