precommit copyright check is broken for updated files
Observed Behavior
Modify an existing file whose copyright header is in the prior year. Stage the file via git add. Now run yarn run precommit
. The precommit check returns ok even though the copyright header is stale. Commit the changes, anyway, then stage more changes involving the same file. Now run yarn run precommit
. You will see it complain about the stale copyright header (because there is a commit with changes and a stale copyright in the history).
Desired Behavior
The precommit check should fail warning the user that the copyright header needs to be updated, just like it does for a new file.
Reproducing the error
To reproduce the error, checkout the copyright-repro
branch on this repository. Then do git reset HEAD^; git add .
. Then run yarn run precommit
and notice that there is no error for jsx.tsx
Cause and Potential Fix.
The root cause of this bug is that copyright-header
used by scripts/copyright.js
only looks at the history of existing commits (via git log --follow) to see if the copyright header is stale. This check works if the file has no history, but fails if the only changes are newer than the copyright header year are in the git cached (staged). The fix is to make a PR for the copyright-header
package that adds a flag to check the staging area as well as the commit history.