{"thread":{"id":"18694","subject":"[PATCH] Fix 'git checkout <submodule>' to update the index","startedAt":"2009-04-02T13:30:25Z","lastAt":"2009-04-02T20:27:52Z","messageCount":3,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"110213","messageId":"c267451c12c4ead4c222eebe6df460b46edd59c1.1238678601u.git.johannes.schindelin@gmx.de","threadId":"18694","inReplyTo":"cover.1238678601u.git.johannes.schindelin@gmx.de","subject":"[PATCH] Fix 'git checkout <submodule>' to update the index","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-02T13:30:25Z","receivedAt":"2009-04-02T13:30:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"While 'git checkout <submodule>' should not update the submodule's\nworking directory, it should update the index.  This is in line with\nhow submodules are handled in the rest of Git.\n\nWhile at it, test 'git reset [<commit>] <submodule>', too.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tI have no idea who thought that it would be a good idea to leave \n\tthe submodules alone, but I think it is highly counterintuitive \n\tthat\n\n\t\tgit checkout <submodule>\n\n\tdoes not touch the index.\n\n\tThis patch fixes it.\n\n\tI'm really swamped with work these days, but happily, this fix was \n\tpart of it: one of my users had a merge conflict in a submodule \n\tand wanted to use the same procedure as for files.\n\n\tIn the meantime, \"git reset <submodule>\" did the job, but this \n\trather limits the user's options:\n\n\t\tgit checkout --theirs <submodule>\n\n\tis a much desired function here.  (Note: I did not test that this \n\tworks, actually, but then, I do not see why it should not, after\n\tthis patch...)\n\n builtin-checkout.c            |    3 --\n t/t2013-checkout-submodule.sh |   42 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 42 insertions(+), 3 deletions(-)\n create mode 100755 t/t2013-checkout-submodule.sh\n\ndiff --git a/builtin-checkout.c b/builtin-checkout.c\nindex 33d1fec..2e4fe1a 100644\n--- a/builtin-checkout.c\n+++ b/builtin-checkout.c\n@@ -53,9 +53,6 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,\n \tint len;\n \tstruct cache_entry *ce;\n \n-\tif (S_ISGITLINK(mode))\n-\t\treturn 0;\n-\n \tif (S_ISDIR(mode))\n \t\treturn READ_TREE_RECURSIVE;\n \ndiff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh\nnew file mode 100755\nindex 0000000..fda3f0a\n--- /dev/null\n+++ b/t/t2013-checkout-submodule.sh\n@@ -0,0 +1,42 @@\n+#!/bin/sh\n+\n+test_description='checkout can handle submodules'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'setup' '\n+\tmkdir submodule &&\n+\t(cd submodule &&\n+\t git init &&\n+\t test_commit first) &&\n+\tgit add submodule &&\n+\ttest_tick &&\n+\tgit commit -m superproject &&\n+\t(cd submodule &&\n+\t test_commit second) &&\n+\tgit add submodule &&\n+\ttest_tick &&\n+\tgit commit -m updated.superproject\n+'\n+\n+test_expect_success '\"reset <submodule>\" updates the index' '\n+\tgit update-index --refresh &&\n+\tgit diff-files --quiet &&\n+\tgit diff-index --quiet --cached HEAD &&\n+\ttest_must_fail git reset HEAD^ submodule &&\n+\ttest_must_fail git diff-files --quiet &&\n+\tgit reset submodule &&\n+\tgit diff-files --quiet\n+'\n+\n+test_expect_success '\"checkout <submodule>\" updates the index only' '\n+\tgit update-index --refresh &&\n+\tgit diff-files --quiet &&\n+\tgit diff-index --quiet --cached HEAD &&\n+\tgit checkout HEAD^ submodule &&\n+\ttest_must_fail git diff-files --quiet &&\n+\tgit checkout HEAD submodule &&\n+\tgit diff-files --quiet\n+'\n+\n+test_done\n-- \n1.6.2.1.493.g67cf3\n"},{"id":"110239","messageId":"7vprfuesra.fsf@gitster.siamese.dyndns.org","threadId":"18694","inReplyTo":"c267451c12c4ead4c222eebe6df460b46edd59c1.1238678601u.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] Fix 'git checkout <submodule>' to update the index","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-02T19:54:17Z","receivedAt":"2009-04-02T19:54:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <johannes.schindelin@gmx.de> writes:\n\n> While 'git checkout <submodule>' should not update the submodule's\n> working directory, it should update the index.  This is in line with\n> how submodules are handled in the rest of Git.\n>\n> While at it, test 'git reset [<commit>] <submodule>', too.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>\n> \tI have no idea who thought that it would be a good idea to leave \n> \tthe submodules alone, but I think it is highly counterintuitive \n> \tthat\n>\n> \t\tgit checkout <submodule>\n>\n> \tdoes not touch the index.\n\nI do not see anything that treats submodule specially in the scripted\nversion and this check for S_ISGITLINK() has been there since the very\nbeginning of C rewrite 782c2d6 (Build in checkout, 2008-02-07), so it is a\nregression fix that can go to maint (all the way down to 1.5.5 if you\nwant).\n\nThanks.\n"},{"id":"110246","messageId":"alpine.DEB.1.00.0904022227400.7464@intel-tinevez-2-302","threadId":"18694","inReplyTo":"7vprfuesra.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Fix 'git checkout <submodule>' to update the index","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-02T20:27:52Z","receivedAt":"2009-04-02T20:27:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 2 Apr 2009, Junio C Hamano wrote:\n\n> Johannes Schindelin <johannes.schindelin@gmx.de> writes:\n> \n> > While 'git checkout <submodule>' should not update the submodule's\n> > working directory, it should update the index.  This is in line with\n> > how submodules are handled in the rest of Git.\n> >\n> > While at it, test 'git reset [<commit>] <submodule>', too.\n> >\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> >\n> > \tI have no idea who thought that it would be a good idea to leave \n> > \tthe submodules alone, but I think it is highly counterintuitive \n> > \tthat\n> >\n> > \t\tgit checkout <submodule>\n> >\n> > \tdoes not touch the index.\n> \n> I do not see anything that treats submodule specially in the scripted \n> version and this check for S_ISGITLINK() has been there since the very \n> beginning of C rewrite 782c2d6 (Build in checkout, 2008-02-07), so it is \n> a regression fix that can go to maint (all the way down to 1.5.5 if you \n> want).\n\nI would appreciate that.\n\nThanks,\nDscho\n"}]}