문제

How could we write a commit-msg hook, for appending a string [XYZ] to all commits, except when the original commit message has [exclude-XYZ] in it somewhere?

I am a beginner with shell scripting and here is what I have tried unsuccessfully so far:

if echo "$1" | grep "[exclude-XYZ]"
then 
else echo "$1 [XYZ]" >> "$1"
fi
도움이 되었습니까?

해결책

You're echoing the filename, rather than checking its contents. Try something like:

if fgrep '[exclude-XYZ]' -- "$1" >/dev/null; then 
  :
else
  echo "[XYZ]" >> "$1"
fi

Or, as a one-liner:

fgrep '[exclude-XYZ]' -- "$1" >/dev/null || echo '[XYZ]' >> "$1"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top