{"thread":{"id":"27039","subject":"switching branches when they use different submodule remotes","startedAt":"2011-04-08T17:52:16Z","lastAt":"2011-04-08T20:45:01Z","messageCount":2,"participants":["Stephen Bannasch","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"165433","messageId":"p0624080dc9c4f8ff178c@[192.168.1.122]","threadId":"27039","inReplyTo":null,"subject":"switching branches when they use different submodule remotes","fromName":"Stephen Bannasch","fromEmail":"stephen.bannasch@deanbrook.org","sentAt":"2011-04-08T17:52:16Z","receivedAt":"2011-04-08T17:52:16Z","isPatch":false,"sender":{"key":"stephen.bannasch@deanbrook.org","avatar":null},"body":"I was confused earlier today when I switched branches in a repo with libgit2 in a submodule.\n\nI knew that the different branches used different remotes for the submodule -- one remote is older, the other remote has newer \ndevelopment.\n\n   git://github.com/pieter/libgit2.git\n   git://repo.or.cz/libgit2.git\n\nso when I switched I deleted the whole libgit2 dir and ran:\n\n   git submodule init\n   git submodule update\n\nI was switching to the branch that referenced git://github.com/pieter/libgit2.git and\nI was surprised the newer branch was cloned instead.\n\nLooking at the doc for git submodule:\n\n   http://www.kernel.org/pub/software/scm/git/docs/git-submodule.html\n\nit made it clear that executing init does not alter existing information in .git/config so I deleted the reference in \n./git/config manually and started over.\n\nIs there a better way to handle this?\n"},{"id":"165456","messageId":"7vei5c322a.fsf@alter.siamese.dyndns.org","threadId":"27039","inReplyTo":"p0624080dc9c4f8ff178c@[192.168.1.122]","subject":"Re: switching branches when they use different submodule remotes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-08T20:45:01Z","receivedAt":"2011-04-08T20:45:01Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stephen Bannasch <stephen.bannasch@deanbrook.org> writes:\n\n> it made it clear that executing init does not alter existing\n> information in .git/config so I deleted the reference in ./git/config\n> manually and started over.\n>\n> Is there a better way to handle this?\n\nPerhaps \"submodule sync\"?\n\nThere are at least two different scenarios where you may have multiple\nURLs for a given submodule path.\n\n - These two URLs may represent two projects with different histories, and\n   depending on the commit that is checked out, your superproject may want\n   to use a URL for the repository that appears in .gitmodules that is\n   checked out.  \"submodule sync\" would be one solution for this case.\n\n - These two URLs may represent a single project but the repository\n   migrated and the old URL may not even work anymore.  In such a case,\n   even when you checked out an old commit of the superproject, you do not\n   want to use the old and now decommissioned URL in the .gitmodules file.\n\nThere can be combinations and variants of the above two.\n\nIn very early days of \"git submodule\" Porcelain support, there were a lot\nof design discussion taking these two situations into account.  I don't\nrecall the details, but the core idea was:\n\n - record a tuple <the value chosen by the user, the value the user saw in\n   .gitmodules when the user chose the value> in .git/config;\n\n - when .gitmodules has a value that the user has not seen, ask the user\n   what to do. The user may want to use the value recorded in .gitmodules,\n   or may want to use the value already in .git/config.  This would result\n   in a new tuple <the value chosen, the value in .gitmodules> recorded in\n   .git/config;\n\n - when .gitmodules has a value that the user has seen, use the\n   corresponding value the user chose to use.\n\nwhich would have solved both use cases; unfortunately, nobody has been\ninclined to implement anything like that so far.\n"}]}