.gitmodules gets updated by different script, now I am trying to find the name and path of the submodule whose URL has changed, below code works, but there should be a better way?
#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 file looks as below, say if bbb's url has changed, then I need to get its name bbb
and path 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
You can try using a git submodule foreach
loop.
It does have:
$name
set to the name $sm_path
set to the path That would avoid grepping the .gitmodules
itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.