#!/bin/bash

vcsname="$(./vcs-name)"

if [ "$vcsname" == "git" ]
then
git show-ref 'refs/heads/master' | tr ' ' '\n' | head -n 1
exit 0
fi

if [ "$vcsname" == "hg" ]
then
hgrevno=$(hg log -r-1 --template='{node}')
for x in . .. ../..
do
if [ -f "$x/.hg/git-mapfile" ]
then
cat "$x/.hg/git-mapfile" | grep "$hgrevno$" | tr ' ' '\n' | head -n 1
exit 0
fi
done
fi

if [ "$vcsname" == "bzr" ]
then
bzr log -r-1 | grep git | head -n 1 | tr ' ' '\n' | tail -n 1
exit 0
fi

if [ "$(pwd | grep unetbootin-source-[0-9])" != "" ]
then
pwd | tr '/' '\n' | grep 'unetbootin-source-' | sed "s/unetbootin-source-//"
exit 0
fi

if [ "$(pwd | grep unetbootin-[0-9])" != "" ]
then
pwd | tr '/' '\n' | grep 'unetbootin-source-' | sed "s/unetbootin-source-//" | grep 'unetbootin-' | sed "s/unetbootin-//"
exit 0
fi

date "+%Y%m%d"

