I am doing similar thing that was asked here Using GitHub Actions to automatically update the repo's submodules and then answered here: https://stackoverflow.com/a/67059629/19741229
The answer works well when the .gitmodules does not have a branch defined for the submodule meaning the branch is main/master. However when the .gitmodules has a branch defined I get an error like this:
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.
Calling git submodule update --remote --recursive
on my local machine seems to be working as expected. But presumably something is different when this is running on GitHub Actions runner. Any help with this?
Things I have tried, but did not help:
- Setting
submodules: recursive
foractions/checkout@v3
- Setting
fetch-depth: 0
foractions/checkout@v3
Update 1: git commands from action checkout log
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.
Update 2: I have determined that for some reason the checkout action does not properly get the remote branches available in the submodule thus like the error says the branch set in the .gitmodules can't be found.
This folder is missing the folder of branch for the submodule:
<runner_repository_folder>\.git\modules\<submodule>\refs\remotes\origin
Possibly this line in the checkout action is the cause?
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>
The next question is, can I force fetching all the remote branches afterwards in my "git pull --recurse-submodules" command? Or maybe something with "git submodule foreach"?