{"thread":{"id":"62510","subject":"Possible bug in Git submodule update --inti","startedAt":"2024-11-18T08:14:33Z","lastAt":"2024-11-19T00:32:04Z","messageCount":3,"participants":["bech","Philippe Blain","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"507471","messageId":"DB9PR10MB709879A45AABEC017F3E89DF8A272@DB9PR10MB7098.EURPRD10.PROD.OUTLOOK.COM","threadId":"62510","inReplyTo":null,"subject":"Possible bug in Git submodule update --inti","fromName":"","fromEmail":"bech","sentAt":"2024-11-18T08:14:27Z","receivedAt":"2024-11-18T08:14:33Z","isPatch":false,"sender":{"key":"bech","avatar":null},"body":"\nHi\n\nI am trying to replace a submodule of a repository with a rewritten version.\nSomebody added a huge json file without enabling lfs, so I cannot move the submodule to GitHub without the rewrite.\n\nThe path of the submodule is: ./Submodules/Lodam.Standard, which I have no intensions of changing.\n\nThe url of the original submodule is: https://lodamrd.visualstudio.com/Features.Net/_git/Lodam.Standard\nThe url of the rewritten submodule is: https://lodamrd.visualstudio.com/Features.Net/_git/Uniware.Standard\n\n\nI planned to do a:\ngit submodule deinit -f <path-to-submodule>\ngit submodule set-url -- <path-to-submodule> <new-url>\ngit submodule update --init <path-to-submodule>\n\nBut actually the sources for the submodule is fetched from the original (same commit SHAs  as before), whereas if I do:\n\ngit submodule deinit -f <path-to-submodule>\ngit submodule set-url -- <path-to-submodule> <new-url>\ngit clone <new-url> <path-to-submodule>\n\nI get the submodule from the new url with the rewritten commit SHA’s.\n\nI have attached the PowerShell output with trace information. I am unfamiliar with git trace, but from line 203 I can see the old url mentioned, where I would expect the new url.\n\nBest regards\n\nSøren Bech Christensen \nSoftware Engineer \nBITZER Electronics A/S\nPC Software Team \nKærvej 75\n6400 Sønderborg // Denmark\nDirect:\t+45 73 42 37 70 \nPhone:\t+45 73 42 37 37 \nMobile:\t+45 25 44 49 65 \nEmail:\tSoeren.Bech@bitzerdk.com \n\n"},{"id":"507531","messageId":"8db6eba3-a151-3819-159b-921a6c3f3242@gmail.com","threadId":"62510","inReplyTo":"DB9PR10MB709879A45AABEC017F3E89DF8A272@DB9PR10MB7098.EURPRD10.PROD.OUTLOOK.COM","subject":"Re: Possible bug in Git submodule update --inti","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2024-11-18T19:22:18Z","receivedAt":"2024-11-18T19:22:21Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Søren,\n\nLe 2024-11-18 à 03:14, Bech Christensen, Søren a écrit :\n> \n> Hi\n> \n> I am trying to replace a submodule of a repository with a rewritten version.\n> Somebody added a huge json file without enabling lfs, so I cannot move the submodule to GitHub without the rewrite.\n> \n> The path of the submodule is: ./Submodules/Lodam.Standard, which I have no intensions of changing.\n> \n> The url of the original submodule is: https://lodamrd.visualstudio.com/Features.Net/_git/Lodam.Standard\n> The url of the rewritten submodule is: https://lodamrd.visualstudio.com/Features.Net/_git/Uniware.Standard\n> \n> \n> I planned to do a:\n> git submodule deinit -f <path-to-submodule>\n\nHere you deinit the submodule, such that the \"submodule Submodules/Lodam.Standard\" section is \nremoved from the config file of the superproject: this submodule is not considered\nactive anymore.\n\n> git submodule set-url -- <path-to-submodule> <new-url>\n\nHere you use 'set-url' to change the submodule URL. The man page states [1]:\n\"Sets the URL of the specified submodule to <newurl>. Then, it will automatically \nsynchronize the submodule’s new remote URL configuration.\"\n\nIn your case, this modifies the 'url' config in the \n\"submodule Submodules/Lodam.Standard\" section of your .gitmodules. \nHowever it does not do anything else, since the submodule \nwas deinitialized above. This is mentioned in the doc for \n'git submodule sync' [2]: \n\"It will only affect those submodules which already have a URL entry \nin .git/config (that is the case when they are initialized or freshly added).\"\n\n> git submodule update --init <path-to-submodule>\n\nThis re-initializes your submodule, which copies the new URL from .gitmodules\nto the 'url' config in the \"submodule Submodules/Lodam.Standard\"\nsection of your '.git/config', as mentioned\nin the doc for 'git submodule init' [3]. Note that this is _not_ \nthe exact command that you ran according to the trace output below, which is:\n\n> D:\\temp\\Mjolnir [develop ≡ +0 ~1 -0 !]>  git submodule update --init --remote ./submodules/Lodam.Standard\n\nNotably the '--remote' flag changes what happens next:\n- without --remote, Git tries to checkout the submodule commit recorded in the superproject\n- with --remote, Git tries to checkout the commit at the tip of the remote HEAD of the submodule [4]\n\nI'll discuss what happens with '--remote' since this is what you appear to be using.\n\nAfter writing the url to '.git/config' as noted above, Git checks if\nit needs to clone the submodule. In your case it does find a Git repository for the \nsubmodule at .git/modules/Lodam.Standard, so it goes on to the next step.\nNext it fetches the submodule remote to get the latest submodule commits\n(since --remote was passed). We can see in the trace output that 'git fetch'\nis invoked. This will thus fetch the default remote in the submodule \n(usually called \"origin\"). The URL used for this fetch is the value of\n'remote.origin.url', which _still_ points to https://lodamrd.visualstudio.com/Features.Net/_git/Lodam.Standard\nbecause none of the previous commands have updated it.\n\n> But actually the sources for the submodule is fetched from the original (same commit SHAs  as before), whereas if I do:\n> \n> git submodule deinit -f <path-to-submodule>\n> git submodule set-url -- <path-to-submodule> <new-url>\n> git clone <new-url> <path-to-submodule>\n> \n> I get the submodule from the new url with the rewritten commit SHA’s.\n\nIf you manually do a 'git clone' you indeed to get the new objects from\nthe new URL, but the Git repository is not put into .git/modules/Submodules/Lodam.Standard\nas is the case with 'git submodule'. Plus, you still have the old repository at \n.git/modules/Submodules/Lodam.Standard, so it is not a good solution in my opinion.\n\nI think what you'd want to do is simply:\n\ngit submodule set-url -- <path-to-submodule> <new-url> \ngit submodule update --init --remote\n\nThis will fetch the new URL and checkout the tip commit of its HEAD branch.\nYou will still have all the objects from the old URL locally though. If you want\nto avoid that, you should completely remove the Git repository of the submodule:\n\ngit submodule set-url -- <path-to-submodule> <new-url> \ngit submodule deinit -f <path-to-submodule>\nrm -rf $(git rev-parse --git-dir)/modules/Submodules/Lodam.Standard\ngit submodule update --init --remote\n\nHope this helps,\nPhilippe.\n\n\n[1] https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-set-url--ltpathgtltnewurlgt\n[2] https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-sync--recursive--ltpathgt82308203\n[3] https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-init--ltpathgt82308203\n[4] https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt---remote\n"},{"id":"507555","messageId":"xmqqldxghxml.fsf@gitster.g","threadId":"62510","inReplyTo":"8db6eba3-a151-3819-159b-921a6c3f3242@gmail.com","subject":"Re: Possible bug in Git submodule update --inti","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-11-19T00:32:02Z","receivedAt":"2024-11-19T00:32:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philippe Blain <levraiphilippeblain@gmail.com> writes:\n\n> Hi Søren,\n> ...\n> in the doc for 'git submodule init' [3]. Note that this is _not_ \n> the exact command that you ran according to the trace output below, which is:\n> ...\n> I think what you'd want to do is simply:\n>\n> git submodule set-url -- <path-to-submodule> <new-url> \n> git submodule update --init --remote\n>\n> This will fetch the new URL and checkout the tip commit of its HEAD branch.\n> You will still have all the objects from the old URL locally though. If you want\n> to avoid that, you should completely remove the Git repository of the submodule:\n>\n> git submodule set-url -- <path-to-submodule> <new-url> \n> git submodule deinit -f <path-to-submodule>\n> rm -rf $(git rev-parse --git-dir)/modules/Submodules/Lodam.Standard\n> git submodule update --init --remote\n\nThanks for a pleasant exchange, RFH with sufficient information\nnecessary to help, with a detailed diagnosis and an alternative\noffered.\n"}]}