#!/bin/bash
ip=$1
branch_name=$2
date=`date "+%Y-%m-%d %H:%M:%S"`

function Git_branch(){
	if [ -z $2 ]; then 
		echo "查看所有服务分支 $date"	
	expect -c "
		set timeout 10
			spawn ssh root@${ip}
		expect \"]#\"
			send \"sh /home/qa-deploy-utils/qa_shell_script/script_by_Contorller/find_branch.sh\r\"
		set timeout -1
		expect \"]#\"
      send \"exit\r\"
		expect eof;"
	else
		echo "查看$2服务的分支 $date"
	expect -c "
		set timeout 10
			spawn ssh root@${ip}
		expect \"]#\"
			send \"cd /home/quant_group/$2\r\"
		expect \"]#\"
			send \"git branch | grep '*';git log -1 | grep Date;\r\"
			set timeout -1
		expect \"]#\"
      send \"exit\r\"
		expect eof;"		
	fi

}

Git_branch $1 $2