Title: Binary file change by hook not detected due to Git textconv · Issue #2742 · pre-commit/pre-commit · GitHub
Open Graph Title: Binary file change by hook not detected due to Git textconv · Issue #2742 · pre-commit/pre-commit
X Title: Binary file change by hook not detected due to Git textconv · Issue #2742 · pre-commit/pre-commit
Description: search you tried in the issue tracker textconv describe your issue I’ve set up Git to use exiftool as a text conversion filter for JPEGs, with this in ~/.config/git/config: [diff "exiftool"] textconv = exiftool --composite -x 'Exiftool:*...
Open Graph Description: search you tried in the issue tracker textconv describe your issue I’ve set up Git to use exiftool as a text conversion filter for JPEGs, with this in ~/.config/git/config: [diff "exiftool"] textco...
X Description: search you tried in the issue tracker textconv describe your issue I’ve set up Git to use exiftool as a text conversion filter for JPEGs, with this in ~/.config/git/config: [diff "exiftool&quo...
Opengraph URL: https://github.com/pre-commit/pre-commit/issues/2742
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Binary file change by hook not detected due to Git textconv","articleBody":"### search you tried in the issue tracker\n\ntextconv\n\n### describe your issue\n\nI’ve set up Git to use `exiftool` as a text conversion filter for JPEGs, with this in `~/.config/git/config`:\r\n\r\n```ini\r\n[diff \"exiftool\"]\r\n textconv = exiftool --composite -x 'Exiftool:*' -x 'File:*' -g0\r\n cachetextconv = true\r\n xfuncname = \"^-.*$\"\r\n```\r\n\r\n…and this in `~/.config/git/attributes`:\r\n\r\n```\r\n*.jpeg diff=exiftool\r\n```\r\n\r\nIn my repo, I’m using `jpegoptim` to optimize JPEG's with the below `.pre-commit-config.yaml`.\r\n\r\nTake an unoptimized JPEG:\r\n\r\n```console\r\n$ git status\r\nOn branch main\r\nChanges to be committed:\r\n new file: donut.jpeg\r\n```\r\n\r\nRunning pre-commit, the hook passes:\r\n\r\n```console\r\n$ pre-commit run jpegoptim\r\nOptimize JPEGs...........................................................Passed\r\n```\r\n\r\n(There’s no option to make `jpegoptim` exit with a non-zero status code when it changes files.)\r\n\r\nHowever, the tool did actually modify the image:\r\n\r\n```console\r\n$ git status\r\nOn branch main\r\nChanges to be committed:\r\n new file: donut.jpeg\r\n\r\nChanges not staged for commit:\r\n modified: donut.jpeg\r\n```\r\n\r\nThis behaviour means commits don't include the optimized version of a flie, instead they’re left around unstaged.\r\n\r\npre-commit doesn't detect the change because the text conversions of the binary file before/after are the same, leading to an empty diff:\r\n\r\n```\r\n$ git diff donut.jpeg\r\n```\r\n\r\nBut using [`--no-textconv`](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---no-textconv) shows the tool actually made a change:\r\n\r\n$ git diff --no-textconv donut.jpeg |cat\r\ndiff --git a/donut.jpeg b/donut.jpeg\r\nindex 3bd0743..d66a2f4 100644\r\nBinary files a/donut.jpeg and b/donut.jpeg differ\r\n```\r\n\r\nThe `git diff` call that pre-commit uses to check for changes, in [`_git_diff()`](https://github.com/pre-commit/pre-commit/blob/e846829992a84ce8066e6513a72a357709eec56c/pre_commit/commands/run.py#L273C6-L277) already uses `--no-ext-diff` to make diffs reproducible\r\nI think it should also use `--no-textconv`.\r\nThis would also make it a little faster.\n\n### pre-commit --version\n\n3.0.3 / main\n\n### .pre-commit-config.yaml\n\n```yaml\nrepos:\r\n- repo: local\r\n hooks:\r\n - id: jpegoptim\r\n name: Optimize JPEGs\r\n entry: jpegoptim\r\n language: system\r\n types: [jpeg]\n```\n\n\n### ~/.cache/pre-commit/pre-commit.log (if present)\n\n_No response_","author":{"url":"https://github.com/adamchainz","@type":"Person","name":"adamchainz"},"datePublished":"2023-02-02T11:00:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2742/pre-commit/issues/2742"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e7ed925c-d9e2-d084-0151-b57d2ba91e10 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B9F2:31738E:8CA661:C9047D:6A58A452 |
| html-safe-nonce | 9ed8a47e6e4f97165d815262278b250c268692c038c21dc1381a02f82c08e827 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOUYyOjMxNzM4RTo4Q0E2NjE6QzkwNDdEOjZBNThBNDUyIiwidmlzaXRvcl9pZCI6IjY3MTMwODcxMDQzNzE5NTg4NjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ad4f892b783bacdef61660dc92a65a5844746a8c16b1018aefb6213543d449b1 |
| hovercard-subject-tag | issue:1567821863 |
| github-keyboard-shortcuts | repository,issues,commits,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pre-commit/pre-commit/2742/issue_layout |
| twitter:image | https://opengraph.githubassets.com/78acb7eafd077af0b244505615df8c13181d7a02c5d56f79e2e6a07feaf5fa59/pre-commit/pre-commit/issues/2742 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/78acb7eafd077af0b244505615df8c13181d7a02c5d56f79e2e6a07feaf5fa59/pre-commit/pre-commit/issues/2742 |
| og:image:alt | search you tried in the issue tracker textconv describe your issue I’ve set up Git to use exiftool as a text conversion filter for JPEGs, with this in ~/.config/git/config: [diff "exiftool"] textco... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | adamchainz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6 |
| turbo-cache-control | no-preview |
| go-import | github.com/pre-commit/pre-commit git https://github.com/pre-commit/pre-commit.git |
| octolytics-dimension-user_id | 6943086 |
| octolytics-dimension-user_login | pre-commit |
| octolytics-dimension-repository_id | 17689377 |
| octolytics-dimension-repository_nwo | pre-commit/pre-commit |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 17689377 |
| octolytics-dimension-repository_network_root_nwo | pre-commit/pre-commit |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width