{"thread":{"id":"62833","subject":"[bug] Using --ignore-space-at-eol with --name-only does not apply the filtering","startedAt":"2025-01-20T13:16:07Z","lastAt":"2025-01-20T16:27:04Z","messageCount":2,"participants":["Bob Ruiken","shejialuo"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"510946","messageId":"CAK_bMgeW6ACsWKDbLk0fvm7DuOo5BYhN2OpA-EyOTCSWrkEXSw@mail.gmail.com","threadId":"62833","inReplyTo":null,"subject":"[bug] Using --ignore-space-at-eol with --name-only does not apply the filtering","fromName":"Bob Ruiken","fromEmail":"bob@synergi.so","sentAt":"2025-01-20T13:15:54Z","receivedAt":"2025-01-20T13:16:07Z","isPatch":false,"sender":{"key":"bob@synergi.so","avatar":null},"body":"Hi,\n\nWhile doing some diffing work today I found a small issue combining a\nfiltering and formatting flag. Let me know if anything is missing in\nthis email, this is my first time reporting a bug here.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\nI'm using \"git diff --name-only\" to analyse the difference between the\ncurrent branch and a target branch.\nThen I wanted to expand the preciseness, I don't actually care about\nspacing differences at the end of lines, for which I use the\n\"--ignore-space-at-eol\" flag.\nThe problem comes in when combining the two flags: when I do \"git diff\n--name-only --ignore-space-at-eol\" the names of the files where only\nspace changes at EOL are happening still appear.\n\nWhat did you expect to happen? (Expected behavior)\nI expect the two flags \"--name-only\" and \"--ignore-space-at-eol\" to\nwork together such that files not matching the latter filter are not\nshown in the output.\n\nWhat happened instead? (Actual behavior)\nThe files that the \"--ignore-space-at-eol\" flag is supposed to filter\nare still shown when \"--name-only\" is used.\n\nWhat's different between what you expected and what actually happened?\nFilenames being resulted that do not match the filters added by flags.\n\nBest regards,\n\nBob\n\n[System Info]\ngit version:\ngit version 2.39.5 (Apple Git-154)\ncpu: arm64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nfeature: fsmonitor--daemon\nuname: Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:14:38\nPDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64\ncompiler info: clang: 16.0.0 (clang-1600.0.26.6)\nlibc info: no libc information available\n$SHELL (typically, interactive shell): /bin/zsh\n"},{"id":"510967","messageId":"Z455pim1i2u_1odm@ArchLinux","threadId":"62833","inReplyTo":"CAK_bMgeW6ACsWKDbLk0fvm7DuOo5BYhN2OpA-EyOTCSWrkEXSw@mail.gmail.com","subject":"Re: [bug] Using --ignore-space-at-eol with --name-only does not apply the filtering","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2025-01-20T16:28:22Z","receivedAt":"2025-01-20T16:27:04Z","isPatch":false,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Mon, Jan 20, 2025 at 03:15:54PM +0200, Bob Ruiken wrote:\n> Hi,\n> \n> While doing some diffing work today I found a small issue combining a\n> filtering and formatting flag. Let me know if anything is missing in\n> this email, this is my first time reporting a bug here.\n> \n> What did you do before the bug happened? (Steps to reproduce your issue)\n> I'm using \"git diff --name-only\" to analyse the difference between the\n> current branch and a target branch.\n> Then I wanted to expand the preciseness, I don't actually care about\n> spacing differences at the end of lines, for which I use the\n> \"--ignore-space-at-eol\" flag.\n> The problem comes in when combining the two flags: when I do \"git diff\n> --name-only --ignore-space-at-eol\" the names of the files where only\n> space changes at EOL are happening still appear.\n> \n\nThanks for your report, this problem could be reproduced in the master\nbranch with the following shell commands:\n\n```sh\ngit init repo && cd repo\nprintf \"foo\\n\" > foo\ngit add foo && git commit -mx && git branch test\nprintf \"foo    \\n\" > foo\ngit add foo && git commit -mx\ngit diff master test --name-only --ignore-space-at-eol\n```\n\n> What did you expect to happen? (Expected behavior)\n> I expect the two flags \"--name-only\" and \"--ignore-space-at-eol\" to\n> work together such that files not matching the latter filter are not\n> shown in the output.\n> \n> What happened instead? (Actual behavior)\n> The files that the \"--ignore-space-at-eol\" flag is supposed to filter\n> are still shown when \"--name-only\" is used.\n> \n\nThis logic is in the \"diff.c::diff_flush\" function, when specifying the\n\"--name-only\" option, it will set the \"DIFF_FORMAT_NAME\" bit which will\nlet the code goes to the following control flow and then exit the\nfunction.\n\n```c\n\tif (output_format & (DIFF_FORMAT_RAW |\n\t\t\t     DIFF_FORMAT_NAME |\n\t\t\t     DIFF_FORMAT_NAME_STATUS |\n\t\t\t     DIFF_FORMAT_CHECKDIFF)) {\n\t\tfor (i = 0; i < q->nr; i++) {\n\t\t\tstruct diff_filepair *p = q->queue[i];\n\t\t\tif (check_pair_status(p))\n\t\t\t\tflush_one_pair(p, options);\n\t\t}\n\t\tseparator++;\n\t}\n```\n\nSo as long as you specify \"--name-only\", from my understanding (maybe\nnot correct here), there is no real diff here. We have just stored the\ninformation about which file is added, modified or deleted by comparing\ntwo trees.\n\nAlthough you have specified \"--ignore-space-at-eol\", the code path does\nnot care about this option at all. Because it simply uses the\ninformation described above to print the difference between the two\ntrees without checking their real contents.\n\nI am not familiar with the code in the diff part, it would cause too\nmuch effort for me to solve this problem. From my perspective, we need to\nexplain more about \"--name-only\" option or we need to make sure that we\ncannot use both \"--name-only\" and \"--ignore-space-at-eol\" options.\n\nThanks,\nJialuo\n"}]}