{"thread":{"id":"45927","subject":"Should \"git submodule update\" accepts --init?","startedAt":"2017-05-11T06:11:08Z","lastAt":"2017-05-11T07:59:42Z","messageCount":3,"participants":["Nazri Ramliy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"319320","messageId":"CAEY4ZpMJbS+-xDKcwbOHCWxAdjOVuTN9DFJNHVqHw0r06CwKJg@mail.gmail.com","threadId":"45927","inReplyTo":null,"subject":"Should \"git submodule update\" accepts --init?","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2017-05-11T06:11:02Z","receivedAt":"2017-05-11T06:11:08Z","isPatch":false,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"Hi,\n\nThe command \"git submodule update\" accepts an \"--init\" flag to\ninitialize an uninitialized submodules.\n\nShouldn't it also accept \"--sync\" flag in order to sync and unsync'd submodule?\n\nOtherwise it seems like I'll have to do \"git submodule update\" twice\nin order to update an already initialized submodule whose upstream\nrepo url has been updated in .gitmodules to point to somewhere new,\nlike so:\n\n$ cd superproject\n$ git pull\n$ git submodule update --init --recursive\nfatal: reference is not a tree: c21784553dcd15e1534773fe3177f39cbb93be65\nUnable to checkout 'c21784553dcd15e1534773fe3177f39cbb93be65' in\nsubmodule path 'path/to/submodule'\nFailed to recurse into submodule path 'path/to/submodule'\n$ git submodule sync\n$ git submodule update --init --recursive\n\nIf the submodule update subcommand accepts the \"--sync\" flag then\nabove can then be simplified to this:\n\n$ cd superproject\n$ git pull\n$ git submodule update --init --sync --recursive\n\nSo the \"--init\" and \"--sync\" flags tells git to initialize an\nuninitialized submodule, and syncs any out-of-sync submodules.\n\nnazri\n"},{"id":"319324","messageId":"xmqqk25nc2s9.fsf@gitster.mtv.corp.google.com","threadId":"45927","inReplyTo":"CAEY4ZpMJbS+-xDKcwbOHCWxAdjOVuTN9DFJNHVqHw0r06CwKJg@mail.gmail.com","subject":"Re: Should \"git submodule update\" accepts --init?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-05-11T06:42:46Z","receivedAt":"2017-05-11T06:42:57Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nazri Ramliy <ayiehere@gmail.com> writes:\n\n> Otherwise it seems like I'll have to do \"git submodule update\" twice\n> in order to update an already initialized submodule whose upstream\n> repo url has been updated in .gitmodules to point to somewhere new,\n\nI am not a heavy submodule user so what I think may not count, but I\nthink the \"upstream\" changing the URL of the submodule should be a\nrare and notable event.  Making it easy to automatically run \"sync\"\nwithout thinking would be a huge mistake---it will make it likely\nfor users to blindly follow what the upstream has in .gitmodules\nwithout checking if the new URL is sensible.\n\nAlso doesn't \"submodule sync\" blindly overwrite URL, even the ones\nthat you tweaked in your configuration to override to point at a\nmirror that is closer to you than the one suggested in .gitmodules?\nIf that is the case, sucn a change to make it easier to run \"sync\"\nwithout thinking is doubly bad, I would think.\n"},{"id":"319337","messageId":"CAEY4ZpO108t=2TxmzeFrzHxeXzJ3V_MGv+fy2gH-ZtOXfP8zUw@mail.gmail.com","threadId":"45927","inReplyTo":"xmqqk25nc2s9.fsf@gitster.mtv.corp.google.com","subject":"Re: Should \"git submodule update\" accepts --init?","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2017-05-11T07:59:34Z","receivedAt":"2017-05-11T07:59:42Z","isPatch":false,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"On Thu, May 11, 2017 at 2:42 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> I am not a heavy submodule user so what I think may not count, but I\n> think the \"upstream\" changing the URL of the submodule should be a\n> rare and notable event.  Making it easy to automatically run \"sync\"\n> without thinking would be a huge mistake---it will make it likely\n> for users to blindly follow what the upstream has in .gitmodules\n> without checking if the new URL is sensible.\n\nYes that would be a mistake for the case when we don't trust upstream.\nBut for the case that we do trust upstream, I would argue that we should\nalways follow what upstream told us to use when it comes to getting the\ncontent of the submodule.\n\n> Also doesn't \"submodule sync\" blindly overwrite URL, even the ones\n> that you tweaked in your configuration to override to point at a\n> mirror that is closer to you than the one suggested in .gitmodules?\n> If that is the case, sucn a change to make it easier to run \"sync\"\n> without thinking is doubly bad, I would think.\n\nFor such use cases I would suggest using url.<pattern>.insteadOf, instead\nof changing what submodule.<name>.url.\n\nMy recent use case that prompted this question (I just realized that I typo'ed\nthe mail subject s/--init/--sync/) is this:\n\nWe are using git submodule for vendoring our Go dependencies. We've been using\nit since 2015 and it has been great for this role. There comes a time when we\nhave to patch the vendored version so we do what is normally done - we fork the\ncode at github and made a pull request. This pull request may get rejected, or\naccepted. For the latter case it may take some time for the acceptance to\nhappen - upstream owner may be away, or there are some cosmetic changes needed\netc, while on our side we need the changes in place for our build (and on\ndeveloper machines) to succeed so that it can be used in production (after\ntesting it in our staging). It is during this time that we want to switch the\nsubmodule url (upstream github repo) to point to another submodule url (our\ngithub repo)\n\nHmm after writing all of the above I wonder if we can't just use\nurl.<pattern>.insteadOf\nto achieve this. But then url.<pattern>.insteadOf feels less official than\nsubmodule.name.<url> so that's another point to think about.\n\nnazri\n"}]}