我正在尝试编写一个脚本,根据我的git repo是子模块还是普通存储库来初始化我的git hooks。它目前的样子如下:
# Get to root directory of client repository
if [[ ":$PATH:" != *":.git/modules:"* ]]; then # Presumed not being used as a submodule
cd ../../
else
cd .. # cd into .git/modules/<nameOfSubmodule> (up one level from hooks)
submoduleName=${PWD##*/} # Get submodule name from current directory
cd ../../../$submoduleName
fi
然而,在测试中,即使我在子模块中,它似乎总是走 else
的路线。
这行代码中是否有什么我忽略的东西,以确定我的路径是否包含了预期的字符?
if [[ ":$PATH:" != ":.git/modules:" ]]
$PATH
和$PWD
? - choroba