{"thread":{"id":"50033","subject":"git-apply working on an index with smudged entries","startedAt":"2018-12-14T10:16:07Z","lastAt":"2018-12-15T00:41:00Z","messageCount":2,"participants":["Christian Halstrick","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"365338","messageId":"CAENte7hRCk+3E+C4LYOjTzQKdqE1wN1=HX7YkR72H+HD-=mj5g@mail.gmail.com","threadId":"50033","inReplyTo":null,"subject":"git-apply working on an index with smudged entries","fromName":"Christian Halstrick","fromEmail":"christian.halstrick@gmail.com","sentAt":"2018-12-14T10:15:47Z","receivedAt":"2018-12-14T10:16:07Z","isPatch":false,"sender":{"key":"christian.halstrick@gmail.com","avatar":"https://gravatar.com/avatar/3598bf518644c7dc32d4dcd8e0554b6a313e12103011862402c83ae2854203ce?d=mp&s=160"},"body":"I see that when I call \"git apply --3way ...\" on an index which was\npreviously created\nby JGit and which contains smudged entries the command fails with\nmessage \"error: foo.txt:\ndoes not match index\". If I do a \"git status\" afterwards and then the\nsame \"git apply --3way ...\" it\nsucceeds. Looks like \"git status\" corrected the index in a way so \"git\napply\" can accept it.\n\nQuestion:\n- is this because the index which jgit created is so corrupt that only\nspecial commands\nlike \"git status\" can repair it?\n- or is \"git apply\" not trying hard enough to consume a index with\nsmudged entries\n\nHere is the trace of a script from Thomas which shows the effect:\n\n> git --version\ngit version 2.19.1\n> jgit --version\njgit version 5.2.0-SNAPSHOT\n> git init\nInitialized empty Git repository in /Users/d032780/tmp/a/.git/\n> echo \"foo\" > foo.txt\n> git add foo.txt\n> git commit -m \"Initial commit\"\n[master (root-commit) ff6c56c] Initial commit\n 1 file changed, 1 insertion(+)\n create mode 100644 foo.txt\n> echo \"bar\" >> foo.txt\n> git add foo.txt\n> git commit -m \"Second commit\"\n[master 2191919] Second commit\n 1 file changed, 1 insertion(+)\n> echo \"baz\" >> foo.txt\n> git add foo.txt\n> git commit -m \"Third commit\"\n[master d863c4a] Third commit\n 1 file changed, 1 insertion(+)\n> git diff HEAD^1..HEAD foo.txt > ../foo.patch\n> jgit reset --hard HEAD~\n> git apply --3way ../foo.patch\nerror: foo.txt: does not match index\n> git ls-files -sv --debug\nH 100644 3bd1f0e29744a1f32b08d5650e62e2e62afb177c 0 foo.txt\n  ctime: 0:0\n  mtime: 1544782273:0\n  dev: 0 ino: 0\n  uid: 0 gid: 0\n  size: 0 flags: 0\n> git status\nOn branch master\nUntracked files:\n...\n> git ls-files -sv --debug\nH 100644 3bd1f0e29744a1f32b08d5650e62e2e62afb177c 0 foo.txt\n  ctime: 1544782273:797529188\n  mtime: 1544782273:796936707\n  dev: 16777220 ino: 64184423\n  uid: 503 gid: 20\n  size: 8 flags: 0\n> git apply --3way ../foo.patch\n> cat foo.txt\nfoo\nbar\nbaz\n>\n"},{"id":"365422","messageId":"xmqqzht7bp0o.fsf@gitster-ct.c.googlers.com","threadId":"50033","inReplyTo":"CAENte7hRCk+3E+C4LYOjTzQKdqE1wN1=HX7YkR72H+HD-=mj5g@mail.gmail.com","subject":"Re: git-apply working on an index with smudged entries","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-12-15T00:40:55Z","receivedAt":"2018-12-15T00:41:00Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Halstrick <christian.halstrick@gmail.com> writes:\n\n> Question:\n> - is this because the index which jgit created is so corrupt that only\n> special commands\n> like \"git status\" can repair it?\n\nNo.\n\n> - or is \"git apply\" not trying hard enough to consume a index with\n> smudged entries\n\nNo.\n\nLower level \"plumbing\" commands like \"git apply\" want to see the\ncached stat information in the index refreshed before they are\ncalled, instead of having to refresh the index themselves before\nstarting to work, for performance reasons.  Higher level \"Porcelain\"\ncommands like \"git status\" on the other hand refreshes the index\nbefore they start to work.\n\nWhat you are seeing is a combination of\n\n * JGit not running its equivalent of \"git update-index --refresh\"\n   before finishing and leaving the index file for you to look at.\n\n * \"git status\" running an equivalent of \"git update-index --refresh\"\n   internally.\n\n * \"git apply\" not running \"update-index --refresh\" itself and\n   instead expecting somebody else to have done so in the sequence\n   of commands that it is a part of.\n\nThe latter two is working perfectly as designed.\n\nI do not know what JGit wanted to do to leave the index in that\nstate, so I cannot judge if that is a reasonable thing to do or JGit\nneeds tobe fixed.\n\n"}]}