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

Re: pre-commit hook returns 409 failure

From: Maddes <maddes_svnlists_at_arcor.de>
Date: 2007-09-17 22:23:10 CEST

Ok, the typical problems with attachments - you forget them :)

Maddes

On 17.09.2007 22:20, Maddes wrote:
> About the 409 error:
> I just searched the web a little bit. Have you already read
> http://svn.haxx.se/users/archive-2007-03/0880.shtml ?
> Maybe updating to 1.4.5 helps.
>
> About the pre-commit hook:
> Please look in the man pages for your sh, if your sh shell does not
> support "declare" then you can not "add" the errors.
> Attached is my typical pre-commit hook script which runs on my Debian
> 4.0r1 "Etch" server. (/bin/sh is bash here)
>
> Maddes
>
> On 17.09.2007 20:37, Jette Derriche wrote:
>> On Sun, 2007-09-16 at 02:48 +0200, Maddes wrote:
>>> I now what you are looking for, and it is fairly easy with some
>>> scripting knowledge.
>>>
>>> My pre-commit hook looks like the following on Linux, where I also do
>>> all the checks possible and only exit at the end, as I don't want the
>>> user to commit and get the first error, commit again and get the second
>>> error, and so on, that's why I "add" the errors.
>> That sounds reasonable...
>>
>>> declare -i RC_ALL=0
>>>
>>> # Make sure that the log message contains some text.
>>> $SVNLOOK log -t "$TXN" "$REPOS" | \
>>> grep "[a-zA-Z0-9]" > /dev/null \
>>> || { RC_ALL+=1; echo -e "$0:\nLog message empty!!!\n " 1>&2; }
>>>
>>> ...
>>>
>>> # All checks done
>>> echo All checks done. RC=${RC_ALL} 1>&2
>>>
>>> # Enable next line when testing
>>> #RC_ALL=999
>>>
>>> exit ${RC_ALL}
>> I have incorporated your script into mine... but now I get:
>>
>> ----------------------
>> svn: 'pre-commit' hook failed with error output:
>> declare: not found
>> RC_ALL+=1: not found
>> svn: MERGE of '/path/to/repo/project': 409 Conflict
>> (http://svn.example.com)
>> ----------------------
>>
>> My script now looks like this...
>>
>>
>> ----------------------
>> #!/bin/sh
>> REPOS="$1"
>> TXN="$2"
>>
>> declare -i RC_ALL=0
>>
>> # Make sure that the log message contains some text.
>> SVNLOOK=/usr/local/bin/svnlook
>> $SVNLOOK log -t "$TXN" "$REPOS" | \
>> grep "[a-zA-Z0-9]" > /dev/null \
>> || { RC_ALL+=1 echo -e "$0:\nLog message empty!!!\n " 1>&2; }
>>
>> # All checks done
>> exit ${RC_ALL}
>> ----------------------
>>
>> Any ideas?
>>
>> /Jette
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
>> For additional commands, e-mail: users-help@subversion.tigris.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: users-help@subversion.tigris.org
>
>

#!/bin/sh

# PRE-COMMIT HOOK
#
# The pre-commit hook is invoked before a Subversion txn is
# committed. Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
# [1] REPOS-PATH (the path to this repository)
# [2] TXN-NAME (the name of the txn about to be committed)
#
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
#
# If the hook program exits with success, the txn is committed; but
# if it exits with failure (non-zero), the txn is aborted, no commit
# takes place, and STDERR is returned to the client. The hook
# program can use the 'svnlook' utility to help it examine the txn.
#
# On a Unix system, the normal procedure is to have 'pre-commit'
# invoke other programs to do the real work, though it may do the
# work itself too.
#
# *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT ***
# *** FOR REVISION PROPERTIES (like svn:log or svn:author). ***
#
# This is why we recommend using the read-only 'svnlook' utility.
# In the future, Subversion may enforce the rule that pre-commit
# hooks should not modify the versioned data in txns, or else come
# up with a mechanism to make it safe to do so (by informing the
# committing client of the changes). However, right now neither
# mechanism is implemented, so hook writers just have to be careful.
#
# Note that 'pre-commit' must be executable by the user(s) who will
# invoke it (typically the user httpd runs as), and that user must
# have filesystem-level permission to access the repository.
#
# On a Windows system, you should name the hook program
# 'pre-commit.bat' or 'pre-commit.exe',
# but the basic idea is the same.
#
# The hook program typically does not inherit the environment of
# its parent process. For example, a common problem is for the
# PATH environment variable to not be set to its usual value, so
# that subprograms fail to launch unless invoked via absolute path.
# If you're having unexpected problems with a hook program, the
# culprit may be unusual (or missing) environment variables.
#
# Here is an example hook script, for a Unix /bin/sh interpreter.
# For more examples and pre-written hooks, see those in
# the Subversion repository at
# http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and
# http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/

SVNLOOK=/usr/bin/svnlook

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

declare -i RC_ALL=0

# Empty line into error log
echo -e " " 1>&2

# Make sure that the log message contains some text.
$SVNLOOK log -t "$TXN" "$REPOS" | \
   grep "[a-zA-Z0-9]" > /dev/null || { RC_ALL+=1; echo -e "$0:\nLog message empty!!!\n " 1>&2; }

# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
#/usr/share/subversion/hook-scripts/commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || { RC_ALL+=1; echo -e "No permission for committing these files!!!\n " 1>&2; }

# Check MIME types
/usr/share/subversion/hook-scripts/check-mime-type.pl "$REPOS" "$TXN" || { RC_ALL+=1; echo -e " " 1>&2; }

# Check case of all names
/usr/share/subversion/hook-scripts/case-insensitive.py "$REPOS" "$TXN" || { RC_ALL+=1; echo -e " " 1>&2; }

# Check forgotten conflicts
# We scan through the transaction diff, looking for things that look
# like conflict markers. If we find one, we abort the commit.
SUSPICIOUS=$($SVNLOOK diff -t "$TXN" "$REPOS" | grep -E '^\+(<{7} \.|={7}$|>{7} \.)' | wc -l)
if [ $SUSPICIOUS -ne 0 ]; then
  RC_ALL+=1
  echo "Some parts of your commit look suspiciously like merge" 1>&2
  echo "conflict markers. Please double-check your diff and try" 1>&2
  echo "committing again." 1>&2
  echo -e " " 1>&2
fi

# All checks done
echo All checks done. RC=${RC_ALL} 1>&2

# Enable next line when testing
#RC_ALL=999

exit ${RC_ALL}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Mon Sep 17 22:23:25 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.