Search code examples
githookpre-commit

Detect modified/added/deleted .tpl files in git pre-commit hook


I am trying to add a pre-commit hook locally on my repository. I want to run a script only if a .tpl file has been modified/added/deleted in the commit. Is there an easy way to check this?

Thank you :-)


Solution

  • You probably need something like this:

    #!/bin/bash
    if git diff --name-only --cached | grep -Eq '\.tpl$'; then
      # do your job
    fi
    

    The --procelain flag guarantees that output won't change in future versions of git (they keep it consistent).