开发者

Unable to write an error message when on a pre-commit hook

开发者 https://www.devze.com 2023-02-17 19:11 出处:网络
I\'m writing a pre-commit hook, or better, I\'m editing the hook that comes standard on the tigris SVN release.

I'm writing a pre-commit hook, or better, I'm editing the hook that comes standard on the tigris SVN release.

My goals are modest, I just want to write an error message to the person who has commited without providing a commit message.

So my thoughts were开发者_开发知识库 to just write to stderr with a simple error message. But for some reason, my messages never seem to get through.

Everyone on the internet says I have got to write to stderr. But somehow that doesn't work.

REPOS="$1"
TXN="$2"


LOG=""
#here is where it seems to wrong
#if [ ${#LOG} -lt 1 ]
        echo "You did not provide a commit message, please try again." 2>&1
#fi

echo
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
   grep "[a-zA-Z0-9]" > LOG || exit 1

# Exit on all errors.
set -e


# All checks passed, so allow the commit.
exit 0

You have to excuse me if this is a silly question, but i'm a linux novice, so apologies beforehand.

thanks, Jasper


Your way of determining the log message is wrong. Try this instead:

SVNLOOK=/usr/bin/svnlook
LOGMSG=`$SVNLOOK log -t “$TXN” “$REPOS” | grep “[a-zA-Z0-9]” | wc -c`

if [ "$LOGMSG" -lt 1 ]; then
  echo -e “Please provide a meaningful comment when committing changes.” 1>&2
  exit 1
fi


Your code:

echo "You did not provide a commit message, please try again." 2>&1

does NOT print to stderr (instead it redirects stderr to stdout). Use instead (important is the 1>&2):

echo "You did not provide a commit message, please try again." 1>&2
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号