|
|
#/bin/bash
|
|
|
|
|
|
function usage(){
|
|
|
echo "----------------------------------"
|
|
|
echo "参数说明:"
|
|
|
echo "-t : 操作类型"
|
|
|
echo "-f : 父路径"
|
|
|
echo "-c : 文件名"
|
|
|
echo ""
|
|
|
echo "举例:sh git.sh -t \"reset_pull\" -f /opt/jmeter/script -c test.jmx"
|
|
|
echo "----------------------------------"
|
|
|
}
|
|
|
|
|
|
if [[ $# -lt 1 ]];then
|
|
|
usage
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
while getopts "t:f:c:" arg
|
|
|
do
|
|
|
case $arg in
|
|
|
t)
|
|
|
gittype=$OPTARG
|
|
|
;;
|
|
|
f)
|
|
|
fatherPath=$OPTARG
|
|
|
;;
|
|
|
c)
|
|
|
filename=$OPTARG
|
|
|
;;
|
|
|
h)
|
|
|
usage
|
|
|
exit 1
|
|
|
;;
|
|
|
?)
|
|
|
echo "未知的参数!"
|
|
|
exit 1
|
|
|
;;
|
|
|
esac
|
|
|
done
|
|
|
|
|
|
if [[ "$gittype" == "reset_pull" && -n "$fatherPath" ]];then
|
|
|
cd $fatherPath
|
|
|
pwd
|
|
|
git reset --hard origin/master
|
|
|
git pull
|
|
|
fi
|
|
|
|
|
|
if [[ "$gittype" == "add_push" && -n "$fatherPath" && -n "$filename" ]];then
|
|
|
cd $fatherPath
|
|
|
pwd
|
|
|
git add $filename
|
|
|
git commit -m "commit by shell"
|
|
|
git push
|
|
|
fi |
...
|
...
|
|