[Bug]: Committing with no changes to the repo results in changes from the pre-commit hook
osis opened this issue · comments
Current Behavior:
When I check out the latest master, do no changes, and try to commit do a commit there are a number of changes that are generated.
Expected Behavior:
The pre-commit hook shouldn't generate changes that differ from what's in the main branch.
Steps to Reproduce:
- Check out
main
- Generate a commit
Environment:
- OS: Ubuntu 20.04
- Node: 18.19.0
- npm: 10.2.3
Anything else we need to know?
The two types of diffs that show up that are not getting linted by lint-staged
are...
- "enum": ["DAILY", "MONTHLY", "QUARTERLY", "SEMI_ANNUAL", "ANNUAL"],
+ "enum": [
+ "DAILY",
+ "MONTHLY",
+ "QUARTERLY",
+ "SEMI_ANNUAL",
+ "ANNUAL"
+ ],
-}
+}
\ No newline at end of file
Full diff of changes can be seen in #474
@osis I was unable to reproduce this with the version of Node in the .nvmrc file. Also that version of npm is incompatible with the engines
block of the package file so you should have gotten a warning.
When you say "generate a commit" -- is it an empty commit, or a commit changing a particular file?
@pjohnmeyer it's an empty commit.
That's odd because lint-staged
doesn't normally allow an empty commit. To make sure it wasn't anything weird about my environment I made a fresh clone and went through the steps:
gh repo clone Open-Cap-Table-Coalition/Open-Cap-Format-OCF
cd Open-Cap-Format-OCF/
nvm use
npm install
git commit --allow-empty -m 'Testing #476'
This did not generate a commit at all, much less commit a modified file.
I wouldn't expect your Node or npm versions to cause this behavior, but please try with the current toolchain and see if it makes a difference.
Output:
plj1@pop-os:~/code/oct$ gh repo clone Open-Cap-Table-Coalition/Open-Cap-Format-OCF Cloning into 'Open-Cap-Format-OCF'... remote: Enumerating objects: 18798, done. remote: Counting objects: 100% (1589/1589), done. remote: Compressing objects: 100% (426/426), done. remote: Total 18798 (delta 1099), reused 1339 (delta 955), pack-reused 17209 Receiving objects: 100% (18798/18798), 7.86 MiB | 4.30 MiB/s, done. Resolving deltas: 100% (14949/14949), done. plj1@pop-os:~/code/oct$ cd Open-Cap-Format-OCF/ plj1@pop-os:~/code/oct/Open-Cap-Format-OCF$ nvm use Found '/home/plj1/code/oct/Open-Cap-Format-OCF/.nvmrc' with version <v18.16.0> Now using node v18.16.0 (npm v9.5.1) plj1@pop-os:~/code/oct/Open-Cap-Format-OCF$ npm install npm WARN deprecated stringify-package@1.0.1: This module is not used anymore, and has been replaced by @npmcli/package-json npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin. npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead > prepare > husky install husky - Git hooks installed added 1156 packages, and audited 1157 packages in 8s 143 packages are looking for funding run `npm fund` for details 16 vulnerabilities (6 moderate, 8 high, 2 critical) To address issues that do not require attention, run: npm audit fix To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. plj1@pop-os:~/code/oct/Open-Cap-Format-OCF$ git commit --allow-empty -m 'Testing #476' > schema:enforce-copyright-notices > node --loader ts-node/esm --no-warnings --experimental-json-modules ./utils/schema-utils/EnforceCopyrightNotices.ts check-notices -fvart --tag main ENFORCE COPYRIGHT NOTICES ---------------------- force_overwrite: true add_missing_comments: true tag: main test: true Traverse schema dir for schema paths... ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... SNIP ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ https://raw.githubusercontent.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/main/schema/enums/ValuationType.schema.json https://raw.githubusercontent.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/main/schema/enums/VestingDayOfMonth.schema.json https://raw.githubusercontent.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/main/schema/enums/VestingTriggerType.schema.json Finished. /home/plj1/code/oct/Open-Cap-Format-OCF ✔ Preparing lint-staged... ✔ Running tasks for staged files... ✖ Prevented an empty git commit! ✔ Reverting to original state because of errors... ✔ Cleaning up temporary files... ⚠ lint-staged prevented an empty git commit. Use the --allow-empty option to continue, or check your task configuration husky - pre-commit hook exited with code 1 (error)
So @pjohnmeyer, agreed that the empty commits should be blocked. That said, I think we discussed seeing similar behavior in the past where the linter was making these changes sometimes. We never did track it down. @osis, have you seen other situations where the changes are created except an empty commit?