首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用git-config从配置文件中获取节名和其他属性

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

Stack Overflow用户
提问于 2019-11-12 04:41:28
回答 1查看 57关注 0票数 1

.gitmodules是由不同的脚本更新的,现在我正在尝试查找URL已更改的子模块的名称和路径,下面的代码可以工作,但应该有更好的方法吗?

代码语言:javascript
复制
#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

代码语言:javascript
复制
$ 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
EN

回答 1

Stack Overflow用户

发布于 2019-11-12 14:05:45

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

它确实有:

设置为name

  • $sm_path
  • $name设置为path

这将避免.gitmodules本身变得贪婪。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58808418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档