Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to create a bash script for a git pre-commit hook. Whenever a commit is made, I want to check if files in a certain directory are part of the staged files and if so, run a command (Grunt task). So far I have everything working, except for only running if certain files are modified. I'm trying to get this to work:

SRC_PATTERN="site/assets/js/"
if [ grep --quiet $SRC_PATTERN `git diff --cached --name-only` ]
then
  echo "none"
  exit 0
fi

This is unfortunately giving me errors.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

try,

git diff --cached --name-only | if grep --quiet "$SRC_PATTERN"
then
    ...

Happy hacking

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.