{"thread":{"id":"62193","subject":"git diff --exit-code misbehaving in 2.46.x","startedAt":"2024-09-25T14:27:59Z","lastAt":"2024-09-25T18:06:35Z","messageCount":4,"participants":["Jan Wendland","René Scharfe","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"503469","messageId":"CAB0mhhz9LHZ1AWSu_0oM=c89+z0w=XemnQwFAm45wp8zSmQ1Sw@mail.gmail.com","threadId":"62193","inReplyTo":null,"subject":"git diff --exit-code misbehaving in 2.46.x","fromName":"Jan Wendland","fromEmail":"jwend1703@gmail.com","sentAt":"2024-09-25T14:27:47Z","receivedAt":"2024-09-25T14:27:59Z","isPatch":false,"sender":{"key":"jwend1703@gmail.com","avatar":null},"body":"Hey team,\n\ngit diff --exit-code in 2.46.x is unexpectedly returning a zero exit\ncode for files marked as binary in .gitattributes where 2.45.x would\ncorrectly produce a non-zero exit code.\n\nTo reproduce:\nmkdir -p git-exit-code/dist\ncd git-exit-code\ngit init\necho \"hi\" > dist/main.js\necho \"dist/** binary\" > .gitattributes\ngit add --all\ngit commit -m \"Initial commit\"\necho \"some change\" >> dist/main.js\ngit diff --exit-code\necho $? # actual is 0, expected to be 1\n\nIs this intended?\n\nKind regards\nJan\n"},{"id":"503471","messageId":"e3da5c9b-c208-4937-a2b4-e1028f3e6841@web.de","threadId":"62193","inReplyTo":"CAB0mhhz9LHZ1AWSu_0oM=c89+z0w=XemnQwFAm45wp8zSmQ1Sw@mail.gmail.com","subject":"Re: git diff --exit-code misbehaving in 2.46.x","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2024-09-25T15:26:59Z","receivedAt":"2024-09-25T15:27:11Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 25.09.24 um 16:27 schrieb Jan Wendland:\n> Hey team,\n>\n> git diff --exit-code in 2.46.x is unexpectedly returning a zero exit\n> code for files marked as binary in .gitattributes where 2.45.x would\n> correctly produce a non-zero exit code.\n>\n> To reproduce:\n> mkdir -p git-exit-code/dist\n> cd git-exit-code\n> git init\n> echo \"hi\" > dist/main.js\n> echo \"dist/** binary\" > .gitattributes\n> git add --all\n> git commit -m \"Initial commit\"\n> echo \"some change\" >> dist/main.js\n> git diff --exit-code\n> echo $? # actual is 0, expected to be 1\n>\n> Is this intended?\n\nThanks for the report!  This is a known bug.  The \"next\" branch contains\na fix, 9a41735af6 (diff: report modified binary files as changes in\nbuiltin_diff(), 2024-09-21).\n\nRené\n\n"},{"id":"503477","messageId":"xmqqbk0bpt5e.fsf@gitster.g","threadId":"62193","inReplyTo":"e3da5c9b-c208-4937-a2b4-e1028f3e6841@web.de","subject":"Re: git diff --exit-code misbehaving in 2.46.x","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-09-25T16:58:21Z","receivedAt":"2024-09-25T16:58:25Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> Am 25.09.24 um 16:27 schrieb Jan Wendland:\n>>\n>> git diff --exit-code in 2.46.x is unexpectedly returning a zero exit\n>> code for files marked as binary in .gitattributes where 2.45.x would\n>> correctly produce a non-zero exit code.\n>> ...\n> Thanks for the report!  This is a known bug.  The \"next\" branch contains\n> a fix, 9a41735af6 (diff: report modified binary files as changes in\n> builtin_diff(), 2024-09-21).\n\nI just noticed something curious.\n\n9a41735a (diff: report modified binary files as changes in\nbuiltin_diff(), 2024-09-21) explains that since 1aaf69e6 (diff:\nshortcut for diff'ing two binary SHA-1 objects, 2014-08-16) added\nbinary comparison, the code path always used a quick hash-only\ncomparison.  But the above report claims it is a behaviour change\nbetween 2.45 and 2.46.\n\nIt does seem to say things are different with 2.45 when binary\nchanges were checked with --quiet/--exit-code from my manual\ntesting, though.\n\nThanks.\n"},{"id":"503487","messageId":"161b4e83-0aa5-4b98-a1c7-b6e1070629d1@web.de","threadId":"62193","inReplyTo":"xmqqbk0bpt5e.fsf@gitster.g","subject":"Re: git diff --exit-code misbehaving in 2.46.x","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2024-09-25T18:06:30Z","receivedAt":"2024-09-25T18:06:35Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 25.09.24 um 18:58 schrieb Junio C Hamano:\n> René Scharfe <l.s.r@web.de> writes:\n>\n>> Am 25.09.24 um 16:27 schrieb Jan Wendland:\n>>>\n>>> git diff --exit-code in 2.46.x is unexpectedly returning a zero exit\n>>> code for files marked as binary in .gitattributes where 2.45.x would\n>>> correctly produce a non-zero exit code.\n>>> ...\n>> Thanks for the report!  This is a known bug.  The \"next\" branch contains\n>> a fix, 9a41735af6 (diff: report modified binary files as changes in\n>> builtin_diff(), 2024-09-21).\n>\n> I just noticed something curious.\n>\n> 9a41735a (diff: report modified binary files as changes in\n> builtin_diff(), 2024-09-21) explains that since 1aaf69e6 (diff:\n> shortcut for diff'ing two binary SHA-1 objects, 2014-08-16) added\n> binary comparison, the code path always used a quick hash-only\n> comparison.  But the above report claims it is a behaviour change\n> between 2.45 and 2.46.\n>\n> It does seem to say things are different with 2.45 when binary\n> changes were checked with --quiet/--exit-code from my manual\n> testing, though.\n\nThere are levels: If the flag diff_from_contents is disabled, diff just\ncompares hashes (and other meta data).  If diff_from_contents is\nenabled, it compares file contents as well.  But not for binary files,\nsince 1aaf69e6 (diff: shortcut for diff'ing two binary SHA-1 objects,\n2014-08-16).\n\nThe shortcut exempts binary files from diff_from_contents.  But it\nforgot to report changes for exit code calculation.  So git diff with\nan option that turns on diff_from_contents (e.g. \"git diff -b -q\")\nhas not been reporting a modified binary file since then.\n\nd7b97b7185 (diff: let external diffs report that changes are\nuninteresting, 2024-06-09) enabled diff_from_contents by default,\nexposing the bug much more widely in 2.46.0.\n\nRené\n\n"}]}