This commit is contained in:
Leon 2021-08-08 20:26:29 +08:00
parent 7e177b77ef
commit 8a6c33197a

45
Scripts/sh/gitsync.sh Normal file
View File

@ -0,0 +1,45 @@
#!/bin/bash
# =========================
# git 同步脚本
#
# Author: 余小波
# Date: 2020-01-09
# =========================
# 本地文件是否发生了改变
is_change=$(git status -s)
# 当前分支
branch=$(git symbolic-ref --short -q HEAD)
# remark
if [ -n "$1" ]; then
guser=$1
else
# git.user.name
guser="$(git config user.name) update"
fi
if [ 0 -lt ${#is_change} ]; then
git add .
git commit -m "$guser"
# pull
result=$(git pull origin $branch)
tmp=$(echo $result | grep "fix conflicts")
if [ "$tmp" != "" ]
then
echo "(=Д=)ノ┻━┻ 合并冲突, 请手动解决后提交"
else
# 推送
git push origin $branch
fi
else
echo "本地没有改变, 正在从远程仓库同步代码. 请耐心等待 ╭(●`∀´●)╯╰(●’◡’●)╮";
result=$(git pull origin $branch)
tmp=$(echo $result | grep "fix conflicts")
if [[ "$tmp" != "" ]]
then
echo "(=Д=)ノ┻━┻ 合并冲突, 请手动解决后提交"
fi
fi