#!/bin/sh

## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.


set -e

TARBALL="${1}"
TARBALLS="${@}"

if [ -z "${TARBALLS}" ]; then
	echo "Usage: ${0} upstream_1.2.3.orig.tar.xz [upstream_1.2.3.orig-foo.tar.xz] [upstream_1.2.3.orig-bar.tar.xz] [...]"
	exit 1
fi

VERSION="$(basename ${TARBALL} | awk -F_ '{ print $2 }' | sed -e 's|.orig.tar.gz||' -e 's|.tar.gz||' -e 's|.orig.tar.bz2||' -e 's|.tar.bz2||' -e 's|.orig.tar.xz||' -e 's|.tar.xz||' -e 's|.orig.tar.lz||' -e 's|.tar.lz||')"

if ! git branch | grep -qs upstream
then
	git branch -m master upstream
fi

for _TARBALL in ${TARBALLS}
do
	echo "P: Adding pristine-tar version ${VERSION} (${_TARBALL})."

	pristine-tar commit -m "Adding pristine-tar version ${VERSION}." ${_TARBALL}
done
