#!/bin/sh
# $Id: bundle2github,v 1.2 2016/06/29 22:58:01 tom Exp $
# Upload a git bundle to github in my "testing" repository.  That can be
# renamed, to provide a "readonly" snapshot.
#
# this works with Debian/testing
# this works with Debian 6.0

MY_NAME="ThomasDickey"

export GIT_COMMITTER_NAME="$MY_NAME"
export GIT_COMMITTER_EMAIL="dickey@his.com"

MY_HUB=git@github.com:$MY_NAME

unset CDPATH
OLDWD=$(pwd)
TARGET=testing
for name in $*
do
	cd $OLDWD
	if test -f "$name"
	then
		SOURCE=$(realpath $name)
		cd /tmp
		rm -f ${TARGET}.bundle
		ln -s $SOURCE ${TARGET}.bundle
		test -d ${TARGET} && rm -rf ${TARGET}
		git clone ${TARGET}.bundle
		cd ${TARGET} || exit 1
		echo "** making branch"
		echo ".. showing branches"
		git branch -a
		echo ".. checking out origin/master"
		git checkout origin/master
		echo ".. showing branches"
		git branch -a
		echo "** adding remote repository"
		git remote rm origin
		git remote add origin $MY_HUB/${TARGET}.git
		echo "** showing remote repository"
		git remote show
		ls -l .git/config
		cat .git/config
		echo "** pushing branch"
		git push -u origin master
		git branch -a
	fi
done
