使用git-config从配置文件中获取节名和其他属性

问题描述 投票:1回答:1

。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
bash git git-config
1个回答
0
投票

您可以尝试使用git submodule foreach循环。

它确实具有:

  • git submodule foreach设置为名称
  • $name设置为路径

这将避免grep $sm_path本身。

© www.soinside.com 2019 - 2024. All rights reserved.