。gitmodules通过不同的脚本进行更新,现在我试图查找URL更改的子模块的名称和路径,下面的代码可以工作,但是应该有更好的方法?
#Check if .gitmodules file has changed.
file_changed=$(git diff --name-only HEAD .gitmodules)
if [[ $file_changed = '.gitmodules' ]]; then
# get all the URLs which were changed.
urls=($(git diff HEAD .gitmodules | grep "^+\s*url" | cut -d' ' -f3))
for url in "${urls[@]}"; do
echo "$url changed"
submod_string=$(git config -f .gitmodules --get-regexp submodule.*.url | grep $url | cut -d' ' -f1)
submod_name=$(echo ${submod_string} | cut -d. -f2)
submod_path=$(git config -f .gitmodules --get-regexp --path submodule.${submod_name}.path | cut -d' ' -f2)
done
fi
。gitmodules文件如下所示,如果bbb的网址已更改,那么我需要获取其名称bbb
和路径BBB
$ cat .gitmodules
[submodule "aaa"]
path = AAA
url = https://blah.com/test/3a
[submodule "bbb"]
path = BBB
url = https://blah.com/test/3b
[submodule "ccc"]
path = CCC
url = https://blah.com/test/3c