0

My .git/hooks/commit-msg file looks like

#!/bin/sh
COMMIT_MSG_FILE=$1
comm_msg=$(head -l $COMMIT_MSG_FILE)
if [[ $comm_msg =~ ^TASKID-[\d]+ ]]; then
  exit 0
else
  echo "Commit message must start with task id." >&2
  exit 1
fi

But when I run

git commit -m "test commit"

I get the error ".git/hooks/commit-msg: 4: .git/hooks/commit-msg: [[: not found. I can't see anything wrong with my syntax. What could be causing this error?

Thundercleez
  • 327
  • 1
  • 4
  • 18
  • 1
    Does this answer your question? [Bash syntax error: "\[\[: not found"](https://stackoverflow.com/questions/3401183/bash-syntax-error-not-found) – Mat Aug 09 '23 at 17:24
  • As an aside, you might want to put anything that can be expanded (such as `$` or `*` parameters) in quotes so they aren't interpreted as part of the command line being executed (e.g. if `COMMIT_MSG_FILE` or `comm_msg` have spaces or valid shell operators). – John Bayko Aug 09 '23 at 17:32
  • Ah, #!/bin/bash instead of sh. Subtle difference I missed! – Thundercleez Aug 09 '23 at 19:00

0 Answers0