checkResult(){
  ret=$?
  if [ $ret != 0 ]
  then
    echo "[$1]执行失败"
    exit 2
    return 0
  else
    echo "[$1]执行成功"
    return 0
  fi
}

echo "安装git提交钩子脚本 cp prepare-commit-msg ./.git/hooks/prepare-commit-msg"  
ls -A ./.git/
ret=$?
if [ $ret != 0 ]
then
  echo "缺少.git文件夹"
  exit 2
fi

ls -A ./.git/hooks/
ret=$?
if [ $ret != 0 ]
then
  mkdir ./.git/hooks
  checkResult '创建hooks文件夹'
fi
cp ./init/prepare-commit-msg ./.git/hooks/prepare-commit-msg
checkResult '复制prepare-commit-msg'
chmod u+x ./.git/hooks/prepare-commit-msg
checkResult '权限变更prepare-commit-msg'