{"thread":{"id":"1023","subject":"[PATCH] git-merge-one-file-script: do not misinterpret rm failure","startedAt":"2005-06-25T06:20:33Z","lastAt":"2005-06-25T06:20:33Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"5256","messageId":"7vpsub555a.fsf@assigned-by-dhcp.cox.net","threadId":"1023","inReplyTo":null,"subject":"[PATCH] git-merge-one-file-script: do not misinterpret rm failure","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-06-25T06:20:33Z","receivedAt":"2005-06-25T06:20:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When a merge adds a file DF and removes a directory there by\ndeleting a path DF/DF, git-merge-one-file-script can be called\nfor the removal of DF/DF when the path DF is already created by\n\"git-read-tree -m -u\".  When this happens, we get confused by a\nfailure return from 'rm -f -- \"$4\"' (where $4 is DF/DF); finding\nfile DF there the \"rm -f\" command complains that DF is not a\ndirectory.\n\nWhat we want to ensure is that there is no file DF/DF in this\ncase. Avoid getting ourselves confused by first checking if\nthere is a file, and only then try to remove it (and check for\nfailure from the \"rm\" command). \n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\ncd /opt/packrat/playpen/public/in-place/git/git.junio/\njit-diff : git-merge-one-file-script\n# - master: Add more tests for read-tree --emu23.\n# + (working tree)\n\ndiff --git a/git-merge-one-file-script b/git-merge-one-file-script\n--- a/git-merge-one-file-script\n+++ b/git-merge-one-file-script\n@@ -22,8 +22,11 @@ case \"${1:-.}${2:-.}${3:-.}\" in\n #\n \"$1..\" | \"$1.$1\" | \"$1$1.\")\n \techo \"Removing $4\"\n-\trm -f -- \"$4\" &&\n-\t\texec git-update-cache --remove -- \"$4\"\n+\tif test -f \"$4\"\n+\tthen\n+\t\trm -f -- \"$4\"\n+\tfi &&\n+\texec git-update-cache --remove -- \"$4\"\n \t;;\n \n #\n\n\n\n"}]}