#!/bin/sh

## Copyright (C) 2006-2014 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

VERSION="${1}"
COMMIT="${2}"

if [ -z "${VERSION}" ]; then
	echo "Usage: $0 VERSION"
	exit 1
fi

if [ ! -d .git ]
then
	# Removing toplevel git metadata
	rm -rf .git*

	git init --shared
fi

git add . -A

git commit -s -S -m "Adding upstream version ${VERSION}."

git-upstream-tag ${VERSION} ${COMMIT}

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