This commit is contained in:
scarqin
2024-12-18 17:32:23 +08:00
parent d8bb1d649c
commit f40f1a4304
2 changed files with 34 additions and 16 deletions
-16
View File
@@ -1,16 +0,0 @@
#!/usr/bin/env sh
# 获取当前分支名
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "post"
# 如果是从 feature 分支推送
if [[ $BRANCH == feature/* || $BRANCH == fix/* ]]; then
# 获取远程仓库列表
REMOTES=$(git remote)
# 检查是否存在 gitlab 和 github 远程仓库
if echo "$REMOTES" | grep -q "gitlab"; then
echo "Pushing $BRANCH to GitLab..."
git push gitlab $BRANCH
fi
fi
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env sh
# 如果是由我们的脚本触发的push,直接返回
if [ "$PUSHING_TO_GITHUB" = "1" ]; then
exit 0
fi
# 获取当前分支名
BRANCH=$(git rev-parse --abbrev-ref HEAD)
# 如果是从 feature 分支推送
if [[ $BRANCH == feature/* || $BRANCH == fix/* ]]; then
# 获取远程仓库列表
REMOTES=$(git remote)
# 检查是否存在 gitlab 远程仓库
if ! echo "$REMOTES" | grep -q "gitlab"; then
echo "Error: GitLab remote repository not found"
exit 1
fi
echo "Pushing $BRANCH to GitLab..."
# 如果存在 github 远程仓库,推送到 GitHub
if echo "$REMOTES" | grep -q "github"; then
echo "Pushing $BRANCH to GitHub..."
PUSHING_TO_GITHUB=1 git push github $BRANCH
fi
exit 0
else
echo "Error: Can only push feature/* or fix/* branches"
exit 1
fi