.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的url已经更改,那么我需要获取它的名称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发布于 2019-11-12 14:05:45
https://stackoverflow.com/questions/58808418
复制相似问题