Title: pre-commit can delete/revert unstaged files if error occurs during git diff-index · Issue #2773 · pre-commit/pre-commit · GitHub
Open Graph Title: pre-commit can delete/revert unstaged files if error occurs during git diff-index · Issue #2773 · pre-commit/pre-commit
X Title: pre-commit can delete/revert unstaged files if error occurs during git diff-index · Issue #2773 · pre-commit/pre-commit
Description: search you tried in the issue tracker diff-index describe your issue I performed a git commit with some modifications unstaged. After the commit, most of the modifications had been reverted and my work was lost. The diff saved in the pat...
Open Graph Description: search you tried in the issue tracker diff-index describe your issue I performed a git commit with some modifications unstaged. After the commit, most of the modifications had been reverted and my ...
X Description: search you tried in the issue tracker diff-index describe your issue I performed a git commit with some modifications unstaged. After the commit, most of the modifications had been reverted and my ...
Opengraph URL: https://github.com/pre-commit/pre-commit/issues/2773
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"pre-commit can delete/revert unstaged files if error occurs during git diff-index","articleBody":"### search you tried in the issue tracker\n\ndiff-index\n\n### describe your issue\n\nI performed a git commit with some modifications unstaged. After the commit, most of the modifications had been reverted and my work was lost. The diff saved in the patch directory had only a few of the modifications in - the ones that survived. The rest were gone.\r\n\r\nTo reproduce:\r\n- Modify four files and stage one with `git add`\r\n- Use `git status` to determine the order of the three unstaged files.\r\n- Change the permission on the middle one so that git will not be able to read it\r\n- Now do `git commit`: the changes to the first unstaged file will be preserved but the other two will be lost.\r\n\r\nThe key point, I think, is that the code in `staged_files_only.py` checks that the return code when creating the diff is non-zero which it takes to mean that the code is `1` meaning that there were diffs. However, in this case the return code is `128` which *is* non-zero but does _not_ mean success - it means error. So the code assumes the diff is OK even though it is incomplete.\n\n### pre-commit --version\n\n2.17.0\n\n### .pre-commit-config.yaml\n\n```yaml\nrepos:\r\n- repo: https://github.com/pre-commit/pre-commit-hooks\r\n rev: 56b4a7e506901ff86f8de5c2551bc41f8eacf717\r\n hooks:\r\n - id: check-yaml\r\n# - id: end-of-file-fixer\r\n - id: trailing-whitespace\r\n- repo: https://github.com/psf/black\r\n rev: 21.11b0\r\n hooks:\r\n - id: black\r\n language_version: python3.6\r\n- repo: https://github.com/PyCQA/isort\r\n rev: 5.10.1\r\n hooks:\r\n - id: isort\r\n args: [\"--profile\", \"black\", \"--filter-files\"]\n```\n\n\n### ~/.cache/pre-commit/pre-commit.log (if present)\n\n_No response_","author":{"url":"https://github.com/strubbly","@type":"Person","name":"strubbly"},"datePublished":"2023-02-21T16:18:01.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2773/pre-commit/issues/2773"}
| 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:586ae21c-208a-b36d-19f9-e4faafdf2067 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB6A:2CEF6D:4EED8C5:6EEAA80:6A570544 |
| html-safe-nonce | 6cf0485b03d7014a028d82c176b7ddd67dc857d9834e035797be9b8ec1f43075 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjZBOjJDRUY2RDo0RUVEOEM1OjZFRUFBODA6NkE1NzA1NDQiLCJ2aXNpdG9yX2lkIjoiMTI4Mjg4ODQ0MDgzMzU3NDIxMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1d3faae8ec40e3ebb92314bdaefe0f97d44fac962142122795c8ade7c5c92cb3 |
| hovercard-subject-tag | issue:1593756040 |
| 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/2773/issue_layout |
| twitter:image | https://opengraph.githubassets.com/173acbcdfa23c8ae7cff7623c7e29e8edf783dd526291c42b6e973293ce26b7a/pre-commit/pre-commit/issues/2773 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/173acbcdfa23c8ae7cff7623c7e29e8edf783dd526291c42b6e973293ce26b7a/pre-commit/pre-commit/issues/2773 |
| og:image:alt | search you tried in the issue tracker diff-index describe your issue I performed a git commit with some modifications unstaged. After the commit, most of the modifications had been reverted and my ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | strubbly |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb29e5f807bd95e41196adfbc6d28f9af12d89830d8b684f3e871774ddff2fc |
| 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 | b056788a129fb0194b61f2ebb4c43f6a9f4dfd27 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width