#!/bin/sh
#=============================================================================#
#               simple menu for git pull from local branch                    #
#=============================================================================#
# (c) Denis Smirnov <mithraen@freesource.info                 	10 Feb 2007   #
#=============================================================================#
# is this git repo?
if [ ! -d .git ]; then
	echo "This is not git repo"
	exit -1
fi

if ! Status; then
	exit -1
fi

B=$(git-show-branchname)

# Generate menu
T_M=`mktemp`
echo '--menu "Select branch for pull to '$B'" 0 0 0' >> $T_M

# Get default
DEFAULT="`git branch | grep '^\*' | sed 's/^..//' | tr -d "\n"`"

# Get list
git branch | grep '^ ' | sed 's/^..\(.*\)/"\1" ""/' | grep -v "^$DEFAULT$" | sort >> $T_M

T1=`mktemp`
dialog --file $T_M 2> $T1
RC=$?
stty sane
clear
if [ $RC -eq 0 ]; then
    git pull . `cat $T1`
fi

rm -f $T_M $T1

