I would like to write a post-checkout, post-merge, and post-rewrite hook that outputs a warning if one specific file has any changes in it. Something along the lines of:
module Overcommit::Hook::PostCheckout
# Checks if the file has changed
class FileCheck < Base
def run
applicable_files.each do |file|
if file == 'the file I care about'
return [:warn, 'the file has changed']
end
end
:pass
end
end
end
In my case, I specifically want to print out something like "Run npm install" whenever the npm-shrinkwrap.json file changes (or possibly even just have overcommit run npm install itself).
Since these hook contexts don't implement modified_files, the applicable_files array is blank and I can't run my check. It looks like git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD might give you the list of files, so I'm hoping that this won't be too difficult to implement.