lfs: don't write hooks when they haven't changed #4935
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some people store their hooks inside their repository. This isn't a secure approach, but in some cases it can be acceptable if all users are trusted.
In such a case, if Git LFS always rewrites a hook even if it hasn't changed, it can result in the file being marked as modified by
git status, sincegit statuscan invoke Git LFS, which in turn invokes Git LFS, which updates the hooks. Thus, the hooks will always appear modified.Let's solve this by not writing the hooks if they haven't changed. We don't include tests here because the only way to determine if changes have occurred is the mtime, and that's difficult to effectively test in the testsuite in a portable way without introducing sleeps, which would make our tests slow.
Fixes #4865