{"thread":{"id":"9882","subject":"[PATCH] apply --index-info: fall back to current index for mode changes","startedAt":"2007-09-17T00:24:57Z","lastAt":"2007-09-17T00:46:23Z","messageCount":2,"participants":["Johannes Schindelin","Chris Shoemaker"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"53239","messageId":"Pine.LNX.4.64.0709170119270.28586@racer.site","threadId":"9882","inReplyTo":null,"subject":"[PATCH] apply --index-info: fall back to current index for mode changes","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-09-17T00:24:57Z","receivedAt":"2007-09-17T00:24:57Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\n\"git diff\" does not record index lines for pure mode changes (i.e. no\nlines changed).  Therefore, apply --index-info would call out a bogus\nerror.\n\nInstead, fall back to reading the info from the current index.\n\nIncidentally, this fixes an error where git-rebase would not rebase a \ncommit including a pure mode change, and changes requiring a threeway \nmerge.\n\nNoticed by Chris Shoemaker.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin-apply.c   |   26 ++++++++++++++++++++++++--\n t/t3400-rebase.sh |   15 +++++++++++++++\n 2 files changed, 39 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 7057d0d..bae4413 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -2215,6 +2215,20 @@ static int check_patch_list(struct patch *patch)\n \treturn err;\n }\n \n+/* This function tries to read the sha1 from the current index */\n+static int get_current_sha1(const char *path, unsigned char *sha1)\n+{\n+\tint pos;\n+\n+\tif (read_cache() < 0)\n+\t\treturn -1;\n+\tpos = cache_name_pos(path, strlen(path));\n+\tif (pos < 0)\n+\t\treturn -1;\n+\thashcpy(sha1, active_cache[pos]->sha1);\n+\treturn 0;\n+}\n+\n static void show_index_list(struct patch *list)\n {\n \tstruct patch *patch;\n@@ -2231,8 +2245,16 @@ static void show_index_list(struct patch *list)\n \t\tif (0 < patch->is_new)\n \t\t\tsha1_ptr = null_sha1;\n \t\telse if (get_sha1(patch->old_sha1_prefix, sha1))\n-\t\t\tdie(\"sha1 information is lacking or useless (%s).\",\n-\t\t\t    name);\n+\t\t\t/* git diff has no index line for mode/type changes */\n+\t\t\tif (!patch->lines_added && !patch->lines_deleted) {\n+\t\t\t\tif (get_current_sha1(patch->new_name, sha1) ||\n+\t\t\t\t    get_current_sha1(patch->old_name, sha1))\n+\t\t\t\t\tdie(\"mode change for %s, which is not \"\n+\t\t\t\t\t\t\"in current HEAD\", name);\n+\t\t\t\tsha1_ptr = sha1;\n+\t\t\t} else\n+\t\t\t\tdie(\"sha1 information is lacking or useless \"\n+\t\t\t\t\t\"(%s).\", name);\n \t\telse\n \t\t\tsha1_ptr = sha1;\n \ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex 62205b2..95e33b5 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -68,4 +68,19 @@ test_expect_success \\\n      test 3 = $(git rev-list master.. | wc -l)\n '\n \n+test_expect_success 'rebase a single mode change' '\n+     git checkout master &&\n+     echo 1 > X &&\n+     git add X &&\n+     test_tick &&\n+     git commit -m prepare &&\n+     git checkout -b modechange HEAD^ &&\n+     echo 1 > X &&\n+     git add X &&\n+     chmod a+x A &&\n+     test_tick &&\n+     git commit -m modechange A X &&\n+     GIT_TRACE=1 git rebase master\n+'\n+\n test_done\n-- \n1.5.3.1.949.g98c3\n"},{"id":"53242","messageId":"20070917004623.GA3826@pe.Belkin","threadId":"9882","inReplyTo":"Pine.LNX.4.64.0709170119270.28586@racer.site","subject":"Re: [PATCH] apply --index-info: fall back to current index for mode changes","fromName":"Chris Shoemaker","fromEmail":"c.shoemaker@cox.net","sentAt":"2007-09-17T00:46:23Z","receivedAt":"2007-09-17T00:46:23Z","isPatch":true,"sender":{"key":"c.shoemaker@cox.net","avatar":null},"body":"On Mon, Sep 17, 2007 at 01:24:57AM +0100, Johannes Schindelin wrote:\n> \n> \"git diff\" does not record index lines for pure mode changes (i.e. no\n> lines changed).  Therefore, apply --index-info would call out a bogus\n> error.\n> \n> Instead, fall back to reading the info from the current index.\n> \n> Incidentally, this fixes an error where git-rebase would not rebase a \n> commit including a pure mode change, and changes requiring a threeway \n> merge.\n> \n> Noticed by Chris Shoemaker.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWorks for me.  Thanks.\n\nAcked-by: Chris Shoemaker <chris.shoemaker@cox.net>\n"}]}