You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Res Pons <po...@hotmail.com> on 2007/03/23 06:06:36 UTC

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

Hi everyone

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/'`
RESULT=$?

        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
                result=$?

                if [[ $result -ne 0 ]]; then

                        echo -n "You must start your comment with a bug 
number, aborting..." 1>&2
                        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
                        exit 1

                fi

        else

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

        fi

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

_________________________________________________________________
5.5%* 30 year fixed mortgage rate. Good credit refinance. Up to 5 free 
quotes - *Terms 
https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h2a5d&s=4056&p=5117&disc=y&vers=910

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

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

Posted by Res Pons <po...@hotmail.com>.
Thanks again for all your help :)

----Original Message Follows----
From: Ryan Schmidt <su...@ryandesign.com>
To: Res Pons <po...@hotmail.com>
CC: users@subversion.tigris.org
Subject: Re: SVN: pre-commit, I give up. Help!
Date: Fri, 23 Mar 2007 15:43:34 -0500

On Mar 23, 2007, at 15:35, Res Pons wrote:

>Thank you for all your help.  Yes one of my main problems was  thinking 
>that $REPO is the fully qualified path of the transaction  including both 
>the svn and the project path!  I see that you  modified the grep to 
>^testproject/trunk.  I would've never thought  of that thinking that $REPO 
>includes everythings!  Now that I see  the modifed script, I have a much 
>better understanding.  As for -n  in echo, what version of svn are you 
>using on your sever? I think  our linux svn version is 1.4.

I have Subversion 1.4.3. For me, Subversion seemed to automatically  include 
a blank line at the end of the error output, so I left in  your echo -n, but 
it probably doesn't matter much one way or the  other whether you leave it 
as echo -n or just use echo.


--

To reply to the mailing list, please use your mailer's Reply To All  
function


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

_________________________________________________________________
Exercise your brain! Try Flexicon. 
http://games.msn.com/en/flexicon/default.htm?icid=flexicon_hmemailtaglinemarch07

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

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

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Mar 23, 2007, at 15:35, Res Pons wrote:

> Thank you for all your help.  Yes one of my main problems was  
> thinking that $REPO is the fully qualified path of the transaction  
> including both the svn and the project path!  I see that you  
> modified the grep to ^testproject/trunk.  I would've never thought  
> of that thinking that $REPO includes everythings!  Now that I see  
> the modifed script, I have a much better understanding.  As for -n  
> in echo, what version of svn are you using on your sever? I think  
> our linux svn version is 1.4.

I have Subversion 1.4.3. For me, Subversion seemed to automatically  
include a blank line at the end of the error output, so I left in  
your echo -n, but it probably doesn't matter much one way or the  
other whether you leave it as echo -n or just use echo.


-- 

To reply to the mailing list, please use your mailer's Reply To All  
function


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

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

Posted by Res Pons <po...@hotmail.com>.
Ryan

Thank you for all your help.  Yes one of my main problems was thinking that 
$REPO is the fully qualified path of the transaction including both the svn 
and the project path!  I see that you modified the grep to 
^testproject/trunk.  I would've never thought of that thinking that $REPO 
includes everythings!  Now that I see the modifed script, I have a much 
better understanding.  As for -n in echo, what version of svn are you using 
on your sever? I think our linux svn version is 1.4.

Thanks for all your help.

Rez

----Original Message Follows----
From: Ryan Schmidt <su...@ryandesign.com>
To: Res Pons <po...@hotmail.com>
CC: Subversion Users <us...@subversion.tigris.org>
Subject: Re: SVN: pre-commit, I give up. Help!
Date: Fri, 23 Mar 2007 02:30:16 -0500

On Mar 23, 2007, at 02:02, Ryan Schmidt wrote:

>On Mar 23, 2007, at 01:06, Res Pons wrote:
>
>>GREP='/bin/grep'

Make sure this is where grep actually is on your system. On mine,  it's in 
/usr/bin/grep.

>>                        echo -n "You must start your comment with a  bug 
>>number, aborting..." 1>&2
>
>Why are you suppressing the newline with -n?

Ah, now that I've played with it a bit, I see that Subversion  automatically 
prints a newline at the end.


So, this is a version that seems to work for me:


#!/bin/bash

# A pre-commit hook script to ensure that no changes are commited to the
# repository without a valid log message.

REPO="$1"
TXN="$2"

SVNLOOK='/opt/local/bin/svnlook'
GREP='/usr/bin/grep'

$SVNLOOK dirs-changed -t "$TXN" "$REPO" | $GREP '^testproject/trunk/'  > 
/dev/null

if [ $? -eq 0 ]; then

	# For testproject, make sure that the comment starts with a (bug)  number
	$SVNLOOK log -t "$TXN" "$REPO" | $GREP '^[[:digit:]]' > /dev/null

	if [ $? -ne 0 ]; then
		echo -n 'For this project, you must start your log message with a  bug 
number.' 1>&2
		exit 1
	fi

else

	# For other projects, no bug number necessary, just make sure the  comment 
isn't empty
	$SVNLOOK log -t "$TXN" "$REPO" | $GREP '[a-zA-Z0-9]' > /dev/null
	if [ $? -ne 0 ]; then
		echo -n 'You must enter some text in your log message.' 1>&2
		exit 1
	fi

fi



--

To reply to the mailing list, please use your mailer's Reply To All  
function

_________________________________________________________________
Interest Rates near 39yr lows! $430,000 Mortgage for $1,399/mo - Calculate 
new payment 
http://www.lowermybills.com/lre/index.jsp?sourceid=lmb-9632-18466&moid=7581

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

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

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Mar 23, 2007, at 02:02, Ryan Schmidt wrote:

> On Mar 23, 2007, at 01:06, Res Pons wrote:
>
>> GREP='/bin/grep'

Make sure this is where grep actually is on your system. On mine,  
it's in /usr/bin/grep.

>>                        echo -n "You must start your comment with a  
>> bug number, aborting..." 1>&2
>
> Why are you suppressing the newline with -n?

Ah, now that I've played with it a bit, I see that Subversion  
automatically prints a newline at the end.


So, this is a version that seems to work for me:


#!/bin/bash

# A pre-commit hook script to ensure that no changes are commited to the
# repository without a valid log message.

REPO="$1"
TXN="$2"

SVNLOOK='/opt/local/bin/svnlook'
GREP='/usr/bin/grep'

$SVNLOOK dirs-changed -t "$TXN" "$REPO" | $GREP '^testproject/trunk/'  
 > /dev/null

if [ $? -eq 0 ]; then
	
	# For testproject, make sure that the comment starts with a (bug)  
number
	$SVNLOOK log -t "$TXN" "$REPO" | $GREP '^[[:digit:]]' > /dev/null
	
	if [ $? -ne 0 ]; then
		echo -n 'For this project, you must start your log message with a  
bug number.' 1>&2
		exit 1
	fi
	
else
	
	# For other projects, no bug number necessary, just make sure the  
comment isn't empty
	$SVNLOOK log -t "$TXN" "$REPO" | $GREP '[a-zA-Z0-9]' > /dev/null
	if [ $? -ne 0 ]; then
		echo -n 'You must enter some text in your log message.' 1>&2
		exit 1
	fi
	
fi



-- 

To reply to the mailing list, please use your mailer's Reply To All  
function


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

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

Posted by Ryan Schmidt <su...@ryandesign.com>.
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"`.

> RESULT=$?

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  
function


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org