1

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?

0xdd
  • 311
  • 3
  • 15

1 Answers1

1

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).

phd
  • 82,685
  • 13
  • 120
  • 165
  • Just knowing whether or not the checkout is a file checkout is sufficient in this script, but thanks a lot for suggesting how to figure out which file's being checked out! – 0xdd Jun 19 '18 at 19:37