[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: SVN: pre-commit, I give up. Help!

From: Ryan Schmidt <subversion-2007a_at_ryandesign.com>
Date: 2007-03-23 08:02:15 CET

On Mar 23, 2007, at 01:06, Res Pons wrote:

> I give up. My new pre-commit script does not work. I even included
> a final echo stmt and an exit code of 1 to cause it failure but
> when I check out the "testproject" and another project, I can, in
> either project, do [svn ci -m "comment" . ] and svn continues
> regardless and checks in the file anyway as seen below:
> Transmitting file data .
> Committed revision 234.
> Here's a copy of my pre-commit:
> sudo vi pre-commit
> #!/bin/bash
> # A pre-commit hook script to ensure that no changes are commited
> to the
> # repository without a valid comment
> #
> REPO="$1"
> TXN="$2"
> SVNLOOK='/usr/bin/svnlook'
> GREP='/bin/grep'
> TESTPROJECT=`echo $REPO | $GREP '/testproject/trunk/'`

REPO is the path to your repository. Not the path within the
repository that is being modified by this transaction, but the actual
on-disk path to your repository. So the above grep will never match,
and TESTPROJECT will always be the empty string. You probably instead
want to grep the result of `$SVNLOOK dirs-changed -t "TXN" $REPO"`.


You get the result of the above grep, but never use it. You probably
should be using this result in the below if statements instead of
testing TESTPROJECT, a variable you probably don't even need.

> if [[ "$TESTPROJECT" ]]; then
> #make sure that the comment starts with a bug number
> and contains some text.
> $SVNLOOK log -t "$TXN" "$REPO" | $GREP '^
> [[:digit:]]' > /dev/null

In fact you're only testing that the log message begins with a single
digit. But if that's enough for you, then ok.

> result=$?
> if [[ $result -ne 0 ]]; then
> echo -n "You must start your comment with a
> bug number, aborting..." 1>&2

Why are you suppressing the newline with -n?

> exit 1
> fi
> elif [[ "$TESTPROJECT" = "" ]]; then
> #if the project is non-testproject, no bug#
> necessary, just force an alphanum comment
> $SVNLOOK log -t "$TXN" "$REPO" | $GREP "[a-zA-Z0-9]"
> > /dev/null
> result=$?
> if [[ $result -ne 0 ]]; then
> echo -n "You must enter an alphanumeric
> comment, aborting..." 1>&2

Same -n remark here.

> exit 1
> fi
> else
> echo "Submission was successful." 1>&2
> exit 0

If your exit code is zero, output is irrelevant; the client will
never see it.

> fi

It seems to me like you have two things you want to do: if one path
in the repo is being modified, you want to do one thing, and if it's
a different path that's being modified, you want to do something
else. Either the grep in the TESTPROJECT assignment matched, or it
didn't. Why then do you have an if, an else if, and an else part
above, making for three choices? It seems like you should only have
an if and an else part, making for two choices.

> echo "WTF?" 1>&2
> exit=1

Should be "exit 1", not "exit=1", which could explain why you weren't
seeing this output in any case.

To reply to the mailing list, please use your mailer's Reply To All  
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Fri Mar 23 08:02:53 2007

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.