#!/bin/bash
# author: itsme@xs4all.nl

# this scripts makes it easier to create tags in svn

if [[ ! -e .svn/entries ]]; then
    echo Not in a svn controlled directory
    exit 1
fi
root=$(awk 'NR==6 { print }'  .svn/entries)
curdir=$(awk 'NR==5 { print }'  .svn/entries)

if [[ $1 == "-h" || $1 == "-?" ]]; then
    echo "Usage:"
    echo "  svntag                 : lists all tags"
    echo "  svntag TAG             : show log message for tag"
    echo "  svntag TAG decription  : create new tag for current directory"
    echo
    exit 0
elif [[ $# == 0 ]]; then
    svn list -v $root/tags/
elif [[ $# == 1 ]]; then
    svn log -v --stop-on-copy $root/tags/$1
else
    name=$1
    shift
    datestamp=$(date +%Y%m%d_%H%M%S)
    if [[ "$root/trunk" != "$curdir" ]]; then
        subdir=$(basename $PWD)
    fi
    svn copy $curdir $root/tags/$datestamp-$subdir-$name -m "$*"
fi
