{"thread":{"id":"24486","subject":"Which is wrong? diff or apply?","startedAt":"2010-07-23T19:03:08Z","lastAt":"2010-07-23T20:49:53Z","messageCount":2,"participants":["Johannes Sixt","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"146105","messageId":"201007232103.08870.j6t@kdbg.org","threadId":"24486","inReplyTo":null,"subject":"Which is wrong? diff or apply?","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2010-07-23T19:03:08Z","receivedAt":"2010-07-23T19:03:08Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Today, I tried this in my git.git checkout:\n\n  $ mv transport-helper.c wt-status.c\n  $ git diff -B -M | git apply --cached\n  error: wt-status.c: already exists in index\n\nThat is, I overwrote the tracked wt-status.c with a completly different file \nthat is also tracked. Then I try to stage the change using git apply.\n\ngit diff -B -M reports this:\n\n  diff --git a/transport-helper.c b/wt-status.c\n  similarity index 100%\n  rename from transport-helper.c\n  rename to wt-status.c\n\nNotice that there is no mention that the previously existing wt-status.c was \nremoved. I wonder whether this is a bug.\n\nOr is it the safety valve in git apply that does not allow to overwrite an \nexisting file which should not trigger in this case?\n\n-- Hannes\n"},{"id":"146111","messageId":"7vzkxhexe6.fsf@alter.siamese.dyndns.org","threadId":"24486","inReplyTo":"201007232103.08870.j6t@kdbg.org","subject":"Re: Which is wrong? diff or apply?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-07-23T20:49:53Z","receivedAt":"2010-07-23T20:49:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n> Today, I tried this in my git.git checkout:\n>\n>   $ mv transport-helper.c wt-status.c\n>   $ git diff -B -M | git apply --cached\n>   error: wt-status.c: already exists in index\n>\n> That is, I overwrote the tracked wt-status.c with a completly different file \n> that is also tracked. Then I try to stage the change using git apply.\n>\n> git diff -B -M reports this:\n>\n>   diff --git a/transport-helper.c b/wt-status.c\n>   similarity index 100%\n>   rename from transport-helper.c\n>   rename to wt-status.c\n>\n> Notice that there is no mention that the previously existing wt-status.c was \n> removed. I wonder whether this is a bug.\n\nHonestly speaking, I would consider this a corner case \"git apply\" bug\nthat nobody cared about so far ;-)\n\nWe can read from the above patch that:\n\n (1) it does not want transport-helper.c in the resulting tree; and\n\n (2) it does want wt-status.c in the resulting tree the same as\n     transport-helper.c from the original tree.\n\nSo I do not think a separate \"deletion\" record is necessary in the diff\noutput.  So far, we have tried (and succeeded, I think) hard to avoid\ncreating diffs that talk about the same path twice in a redundant way.\n\nWhat should \"git apply\" do in this case then?\n\nThe path involved are transport-helper.c (will be removed) and wt-status.c\n(will be rewritten).  The usual \"safety\" rules should apply to both of\nthem when \"apply --index\" is run.  Namely\n\n - transport-helper.c, as it will be removed, should not have difference\n   from the version in the index; and\n\n - wt-status.c, as it will be modified to match transport-helper.c, should\n   not have difference from the version in the index, either.\n\nIf we check the \"renamed-to\" case differently from the \"created-at\" case\n(which I do not think the code does right now), we should be fine, I\nthink.\n"}]}