#!/bin/bash
package=$1
if [ -z "$package" ]
then
	read -p "package is empty,Whether to submit the code in the current directory(y?)!!!" current_directory
fi
if [ ! -z "$current_directory" ]
then
	exit 1
fi
read -p "input commit message: " commit_message
function whether_to_continue(){
	read -p "whether to containue(y/n):" input
	typeset -l input=$input
	echo $input
	if [ $input != "y" ]
	then
		exit 1
	fi
}
function git_add_and_push(){
	echo "git status?"
	whether_to_continue
	git status
	echo "git diff?"
	whether_to_continue
	git diff
	echo "git add -A?"
	whether_to_continue
	git add -A
	git status
	echo "git commit -m $commit_message?"
	whether_to_continue
	git commit -m "$commit_message"
	echo "git push origin HEAD:refs/for/lns8?"
	whether_to_continue
	git push origin HEAD:refs/for/lns8
}
if [ -z $package ]
then
	git_add_and_push
else
	echo "get source code from ~/rpmbuild"
	rm -rf ~/rpmbuild/SOURCES/*
	rm -rf ~/rpmbuild/SPECS/*
	rpm -ivh $package
	cp -r ~/rpmbuild/SOURCES/ .
	cp -r ~/rpmbuild/SPECS/ .
	cat .metadata | awk -F " " '{print $2}' | xargs rm -rf
	git_add_and_push
fi

