File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /bin/sh
22# Git 包装脚本:供 VS Code 通过 git.path 配置使用
33# push 成功后自动同步父仓库 Lab 的子模块指针
4- # 适用于所有两级深度的子模块(Lab/<dir>/<name> )
4+ # 适用于任意深度的子模块(通过 --show-superproject-working-tree 动态定位父仓库 )
55
66REAL_GIT=" /usr/bin/git"
77LOG=" /tmp/git-wrapper.log"
@@ -16,9 +16,12 @@ _exit=$?
1616# 仅在 push 成功时触发同步
1717if [ " $1 " = " push" ] && [ $_exit -eq 0 ]; then
1818 _toplevel=$( " $REAL_GIT " rev-parse --show-toplevel 2> /dev/null)
19- _hook=" $_toplevel /../../.githooks/submodule/post-push"
20- if [ -f " $_hook " ]; then
21- sh " $_hook "
19+ _parent=$( " $REAL_GIT " -C " $_toplevel " rev-parse --show-superproject-working-tree 2> /dev/null)
20+ if [ -n " $_parent " ]; then
21+ _hook=" $_parent /.githooks/submodule/post-push"
22+ if [ -f " $_hook " ]; then
23+ sh " $_hook "
24+ fi
2225 fi
2326fi
2427
Original file line number Diff line number Diff line change 77
88# 子模块根目录 & 父仓库根目录
99SUB_DIR=$( git rev-parse --show-toplevel)
10- # 适用于所有两级深度的子模块(React/source、JS/engine-source 等)
11- PARENT_DIR=$( cd " $SUB_DIR /../.." && pwd)
10+ # 动态定位父仓库,适用于任意深度的子模块
11+ PARENT_DIR=$( git -C " $SUB_DIR " rev-parse --show-superproject-working-tree 2> /dev/null)
12+ if [ -z " $PARENT_DIR " ]; then
13+ echo " [post-push] ERROR: 无法找到父仓库(非子模块环境)" >&2
14+ exit 1
15+ fi
1216
1317# 子模块相对于父仓库的路径,例如 React/Ahooks-source
1418SUB_REL=$( realpath --relative-to=" $PARENT_DIR " " $SUB_DIR " 2> /dev/null \
Original file line number Diff line number Diff line change @@ -27,9 +27,13 @@ git() {
2727 if [ "\$ 1" = "push" ] && [ \$ _exit -eq 0 ]; then
2828 local _toplevel
2929 _toplevel=\$ (command git rev-parse --show-toplevel 2>/dev/null)
30- local _hook="\$ _toplevel/../../.githooks/submodule/post-push"
31- if [ -f "\$ _hook" ]; then
32- sh "\$ _hook"
30+ local _parent
31+ _parent=\$ (command git -C "\$ _toplevel" rev-parse --show-superproject-working-tree 2>/dev/null)
32+ if [ -n "\$ _parent" ]; then
33+ local _hook="\$ _parent/.githooks/submodule/post-push"
34+ if [ -f "\$ _hook" ]; then
35+ sh "\$ _hook"
36+ fi
3337 fi
3438 fi
3539 return \$ _exit
You can’t perform that action at this time.
0 commit comments