I'm writing a post-checkout hook, but I'd like to avoid it being run if certain conditions are met, with one of these being upon checkout of a single touched file. For example, I'd like it to run if I run git checkout somebranch
, but avoid it being run if I just want to git checkout -- some/touched/file
.
As far as I know, the post-checkout
script is only passed the previous and post-checked-out commit hashes, with some additional data being scrapable from the git repo's global state, but I'm not sure what to check to figure out if it's just a single file being checked out.
Is this possible at all? If so how?
The third parameter for post-checkout hook is 1 for branch checkout or 0 for file checkout but there is no way to learn what files just have been checked out.
The only way that comes to my mind — scan the entire worktree and collect files that have modification date very close to the current time (within a few seconds).