#!/bin/sh
#=============================================================================#
#               simple menu for git pull from local branch                    #
#=============================================================================#
# (c) Denis Smirnov <ds@seiros.ru                 				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

# Generate menu
T_M=`mktemp`
echo '--menu "Select branch for checkout" 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" == "0" ]; then
    git pull . `cat $T1`
fi

rm -f $T_M $T1

