GitHub Actions自动更新带分支的仓库子模块报错求助
GitHub Actions自动更新指定分支子模块失败的解决求助
问题描述
我正在实现仓库子模块的自动更新功能,参考的方案在子模块未指定分支(默认main/master)时运行正常,但当.gitmodules中为子模块指定了特定分支后,GitHub Actions执行时出现以下错误:
Run git pull --recurse-submodules git pull --recurse-submodules git submodule update --remote --recursive shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'" Fetching submodule <my submodule> Already up to date. fatal: Unable to find refs/remotes/origin/<my branch> revision in submodule path '<my submodule>' Error: Process completed with exit code 1.
本地执行git submodule update --remote --recursive可正常运行,但在GitHub Actions runner中异常。
已尝试的无效操作
- 为
actions/checkout@v3设置submodules: recursive - 为
actions/checkout@v3设置fetch-depth: 0
排查细节
更新1:checkout动作的Git命令日志
git.exe version git.exe config --global --add safe.directory D:\runners\project-runner\_work\project-repo\project-repo git.exe config --local --get remote.origin.url git.exe rev-parse --symbolic-full-name --verify --quiet HEAD git.exe checkout --detach git.exe rev-parse --symbolic-full-name --branches git.exe branch --delete --force <branch_on_master_repo> git.exe rev-parse --symbolic-full-name --remotes=origin git.exe clean -ffdx git.exe reset --hard HEAD git.exe config --local gc.auto 0 git.exe config --local --name-only --get-regexp core\.sshCommand git.exe submodule foreach --recursive "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :" git.exe config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader git.exe submodule foreach --recursive "git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :" git.exe config --local http.https://github.com/.extraheader "AUTHORIZATION: basic ***" git.exe -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +d055a3ccba731bc9a8d785604528deff7d203548:refs/remotes/origin/<branch_on_master_repo> git.exe checkout --progress --force -B <branch_on_master_repo> refs/remotes/origin/<branch_on_master_repo> git.exe config --global http.https://github.com/.extraheader "AUTHORIZATION: basic ***" git.exe config --global --unset-all url.https://github.com/.insteadOf git.exe config --global --add url.https://github.com/.insteadOf git@github.com: git.exe config --global --add url.https://github.com/.insteadOf org-123456@github.com: git.exe submodule sync git.exe -c protocol.version=2 submodule update --init --force --depth=1 git.exe submodule foreach "git config --local gc.auto 0" git.exe submodule foreach --recursive "git config --local --name-only --get-regexp 'url\.https\:\/\/github\.com\/\.insteadOf' && git config --local --unset-all 'url.https://github.com/.insteadOf' || :" git.exe submodule foreach "git config --local 'http.https://github.com/.extraheader' 'AUTHORIZATION: basic ***' && git config --local --show-origin --name-only --get-regexp remote.origin.url" git.exe submodule foreach "git config --local --add 'url.https://github.com/.insteadOf' 'git@github.com:'" git.exe submodule foreach "git config --local --add 'url.https://github.com/.insteadOf' 'org-123456@github.com:'" git.exe log -1 --format='%H' git pull --recurse-submodules git submodule update --remote --recursive shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'" Fetching submodule <my submodule> Already up to date. fatal: Unable to find refs/remotes/origin/<my branch> revision in submodule path '<my submodule>' Error: Process completed with exit code 1.
更新2:定位到的核心问题
确认checkout动作未正确拉取子模块的远程分支,导致.gitmodules中设置的分支无法被找到。子模块的以下目录缺失对应分支的文件夹:
<runner_repository_folder>\.git\modules\<submodule>\refs\remotes\origin
怀疑是checkout动作中的这条命令导致的:
git.exe -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +d055a3ccba731bc9a8d785604528deff7d203548:refs/remotes/origin/<branch_on_master_repo>
求助问题
能否在git pull --recurse-submodules中强制拉取所有远程分支?或者通过git submodule foreach命令实现相同效果?
内容的提问来源于stack exchange,提问作者Tuomas
相关产品推荐
相关产品推荐

