#!/bin/bash

# claws-mail action command:
# aterm -geometry 80x30 -e $HOME/scripts/claws-git-am.bash linux %F &

function die {
	echo "$1"
	read -p 'Press enter...'
	exit 1
}

function checkpatch {
	if scripts/checkpatch.pl "$@"; then
		return 0
	fi
	read -n 1 -p 'Checkpatch failed, apply anyway (press y)? ' ANS
	echo
	if [[ "$ANS" == y ]]; then
		return 0
	fi
	return 1
}

TAG="$1"
shift
# now "$@" contains all the patch files in given order

case "$TAG" in
#	linux)
#		cd $HOME/linux/linux-2.6-torvalds || die "No git dir!"
#		checkpatch "$@" || die "Aborted."
#		;;
	compiz-core)
		cd $HOME/git/compiz/core || die "No git dir!"
		;;
	wayland)
		cd $HOME/git/wayland || die "No git dor!"
		;;
	wayland-demos)
		cd $HOME/git/wayland-demos || die "No git dor!"
		;;
	*)
		die "error, unknown tag: $TAG"
		;;
esac

echo '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *'
echo 'git-am --signoff' "$@"
echo '-----------------------------------------------------------------------'

if git am --signoff "$@"; then
	read -p 'Ok, press enter...'
else
	echo ' - - - Falling back to shell so you can fix it - - -'
	exec bash -i -s -- "$@"
fi

