{"thread":{"id":"60163","subject":"Submodule update fetching with outer repo's default branch","startedAt":"2023-08-28T23:59:34Z","lastAt":"2023-11-28T18:33:05Z","messageCount":2,"participants":["Scott Shawcroft","Ricardo Abreu"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"481103","messageId":"111c2777-6fd4-45ab-8418-9d064999661c@app.fastmail.com","threadId":"60163","inReplyTo":null,"subject":"Submodule update fetching with outer repo's default branch","fromName":"Scott Shawcroft","fromEmail":"scott@tannewt.org","sentAt":"2023-08-28T23:57:55Z","receivedAt":"2023-08-28T23:59:34Z","isPatch":false,"sender":{"key":"scott@tannewt.org","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\nI have a repo (https://github.com/adafruit/circuitpython) with a large number\nof submodules. When switching branches we have a `make fetch-all-submodules`\ncommand that runs `git submodule update --init` under the hood.\n\nWhat did you expect to happen? (Expected behavior)\nThe data/nvm.toml submodule should update to the commit set by the state of the outer repo.\n\nWhat happened instead? (Actual behavior)\n\nenv GIT_TRACE=1 git submodule update --init data/nvm.toml/\n16:33:38.062849 git.c:749               trace: exec: git-submodule update --init data/nvm.toml/\n16:33:38.062882 run-command.c:659       trace: run_command: git-submodule update --init data/nvm.toml/\n16:33:38.077269 git.c:463               trace: built-in: git rev-parse --git-dir\n16:33:38.079447 git.c:463               trace: built-in: git rev-parse --git-path objects\n16:33:38.083204 git.c:463               trace: built-in: git rev-parse --show-prefix\n16:33:38.085057 git.c:463               trace: built-in: git rev-parse --show-toplevel\n16:33:38.089671 git.c:463               trace: built-in: git submodule--helper update --init -- data/nvm.toml/\n16:33:38.091052 run-command.c:1523      run_processes_parallel: preparing to run up to 1 tasks\n16:33:38.091061 run-command.c:1551      run_processes_parallel: done\n16:33:38.091934 run-command.c:659       trace: run_command: cd data/nvm.toml; unset GIT_PREFIX; GIT_DIR=.git git rev-list -n 1 427cc923976229bcb981ca6f218ebe8efd636df6 --not --all\n16:33:38.093709 run-command.c:659       trace: run_command: cd data/nvm.toml; unset GIT_PREFIX; GIT_DIR=.git git fetch\n16:33:38.094641 git.c:463               trace: built-in: git fetch\n16:33:38.094933 run-command.c:659       trace: run_command: git remote-https origin https://github.com/adafruit/nvm.toml.git\n16:33:38.095835 git.c:749               trace: exec: git-remote-https origin https://github.com/adafruit/nvm.toml.git\n16:33:38.095861 run-command.c:659       trace: run_command: git-remote-https origin https://github.com/adafruit/nvm.toml.git\n16:33:38.352385 run-command.c:1523      run_processes_parallel: preparing to run up to 1 tasks\n16:33:38.352401 run-command.c:1551      run_processes_parallel: done\n16:33:38.352407 run-command.c:659       trace: run_command: git maintenance run --auto --no-quiet\n16:33:38.353616 git.c:463               trace: built-in: git maintenance run --auto --no-quiet\n16:33:38.354265 run-command.c:659       trace: run_command: cd data/nvm.toml; unset GIT_PREFIX; GIT_DIR=.git git rev-list -n 1 427cc923976229bcb981ca6f218ebe8efd636df6 --not --all\n16:33:38.356060 run-command.c:659       trace: run_command: cd data/nvm.toml; unset GIT_PREFIX; GIT_DIR=.git git fetch adafruit321 427cc923976229bcb981ca6f218ebe8efd636df6\n16:33:38.357177 git.c:463               trace: built-in: git fetch adafruit321 427cc923976229bcb981ca6f218ebe8efd636df6\nfatal: transport 'file' not allowed\nfatal: Fetched in submodule path 'data/nvm.toml', but it did not contain 427cc923976229bcb981ca6f218ebe8efd636df6. Direct fetching of that commit failed.\n\n\nWhat's different between what you expected and what actually happened?\nThe submodule update is unable to find the target commit even though it is present in the submodule's repo.\n\nAnything else you want to add:\nLooking at the trace I noticed it's doing `git fetch adafruit321 ...` instead of the correct `git fetch origin ...`. (The `git remote-https origin` command is correct.) adafruit321 is the default branch in `.git/config` for my outer repo's branch (not the submodule). It looks like `fetch_in_submodules` is using the wrong default branch: https://github.com/git/git/blob/next/builtin/submodule--helper.c#L2241C31-L2241C31\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.42.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 6.4.12-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 24 Aug 2023 00:38:14 +0000 x86_64\ncompiler info: gnuc: 13.2\nlibc info: glibc: 2.38\n$SHELL (typically, interactive shell): /usr/bin/fish\n\n\n[Enabled Hooks]\npre-commit\n"},{"id":"485195","messageId":"20231128183253.134480-1-ricardolafabreu@gmail.com","threadId":"60163","inReplyTo":"111c2777-6fd4-45ab-8418-9d064999661c@app.fastmail.com","subject":"Re: Submodule update fetching with outer repo's default branch","fromName":"Ricardo Abreu","fromEmail":"ricardolafabreu@gmail.com","sentAt":"2023-11-28T18:32:53Z","receivedAt":"2023-11-28T18:33:05Z","isPatch":false,"sender":{"key":"ricardolafabreu@gmail.com","avatar":null},"body":"I have the same problem. Here is a generic recipe to reproduce, assuming a repository X with a submodule Y (set with an `https` URL):\n\n1. `git clone ... X`\n2. `cd X`\n3. `git submodule sync`\n4. `git submodule update --init --recursive`\n5. `git remote rename origin remotex` # rename the remote in X, not Y\n6. Elsewhere, add a new commit to Y and create a branch \"update-y\" in X, pointing the submodule to that commit. Suppose the hash of the new commit in Y is `abc1abc`.\n7. `git fetch remotex`\n8. `git checkout update-y`\n9. `git submodule sync`\n10. `GIT_TRACE=1 git submodule update --init --recursive`\n  - observe: \n    * the command in the last trace message to be `git fetch remotex abc1abc` (should be `git fetch origin abc1abc`, because that is still the name of the submodule's remote)\n    * the wrong error message complaining about 'file' protocol (which isn't involved anywhere)\n\n"}]}