diff --git a/.husky/post-push b/.husky/post-push deleted file mode 100755 index 86228fde..00000000 --- a/.husky/post-push +++ /dev/null @@ -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 diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 00000000..0b12edc4 --- /dev/null +++ b/.husky/pre-push @@ -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