Skip to content
Snippets Groups Projects
get_revision 931 B
Newer Older
Karl Fogel's avatar
Karl Fogel committed
#!/bin/sh

# Usage:
#
#   $ get_revision [PATH]
#
# Print the revision number of this SVN working copy, or the git
# revision of the local git repo (if this is a git-svn checkout);
# optional argument PATH means print revision of that file or dir.
#
# If not in an SVN- or git-controlled directory, exit with error.

TARGET="${1-.}"

## Test whether this directory is controlled by svn
if svn info "${TARGET}" > /dev/null 2>&1; then
James Vasile's avatar
James Vasile committed
    echo r`svn info "${TARGET}" | grep "Last Changed Rev: [0-9]" | sed -e 's/Last Changed Rev: //'`
Karl Fogel's avatar
Karl Fogel committed
elif git log --max-count 1 "${TARGET}" > /dev/null 2>&1; then
James Vasile's avatar
James Vasile committed
    echo r`git log "${TARGET}" | grep -m 1 '^\s\+git-svn-id:.*\@[0-9]\+ ' | sed 's/.*@\([0-9]\+\) .*/\1/'`
James Vasile's avatar
James Vasile committed
    # Another way to accomplish the same thing.  Left here just for edification
    # git svn log --limit=1 "${TARGET}" | grep ^r -m 1 | sed "s/ .*//"
Karl Fogel's avatar
Karl Fogel committed
else
  >&2 echo "ERROR: Not an svn working copy nor a git repo."
  exit 1