You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Marc Lustig <ml...@marclustig.com> on 2009/09/24 14:06:20 UTC

implementing pre-commit-hook to prevent overwriting files under tags-dir

Hi,

I found a script in the svn.collab.net repo that is supposed to prevent
overwriting content under the tags-dir.
Since this script is enabled, any commit fails with exit code 255, like:

>Some of selected resources were not committed.
>A repository hook failed
>svn: Commit failed (details follow):
>svn: Übertragen wird durch Aktion pre-commit behindert (Exit-Code 255) ohne
Ausgabe. 


The strange thing is, there is no single "exit 255" command in the script.

To debug this, I simply used the following lines in the script:

echo "starting script" >&2
exit 1

But still, the commit-operation fails WITHOUT the message "starting script"
and with exit-code 255 instead of exit-code 1.

The script has permissions 644 and is owned by root.
The installation is collabnet-rpm-package 1.5.2.

Any idea what is going wrong?
-- 
View this message in context: http://www.nabble.com/implementing-pre-commit-hook-to-prevent-overwriting-files-under-tags-dir-tp25570855p25570855.html
Sent from the Subversion Users mailing list archive at Nabble.com.

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2399292

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Stein Somers <ss...@opnet.com>.
Marc Lustig wrote:
> The bug must be somewhere else.

And you may be hiding it with those "2>/dev/null" everywhere. You use an 
awful lot of text processing tools in that shell script. Better learn some of 
them well and drop the others. For instance, "grep x | sed s/x/y/" probably 
means you want "sed -n s/x/y/p".

The one advantage of shell is you can easily play with it on the command 
line. So do that, add each part of the filter and find out what it does.

-- 
Stein

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400188

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Stein Somers <ss...@opnet.com>.
>>> $ echo aaa/bbb/tags/version/xxx/yyy | sed -E "s|(tags/[^/]+).*$|\1|"
> 
>> no -E option available :(

Using old school regex notation, and -n/p to filter out non-matching lines:

svnlook blah | sed -n 's|^\(.*/tags/[^/]*\)/.*$|\1|p'


-- 
Stein

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2401552

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Andrey Repin <an...@freemail.ru>.
Greetings, Marc Lustig!

>> $ echo aaa/bbb/tags/version/xxx/yyy | sed -E "s|(tags/[^/]+).*$|\1|"
>> aaa/bbb/tags/version

> Looks lovely, but we use GNU sed Version 4.1.2 on Linux, and there is no -E
> option available :(
> Any other way to get this working?

Try "-r" instead of "-E". If not, look in `man sed` for options.
I've been hit by similar issue between cygwin and FreeBSD sed's.

Also, please don't top-post.


--
WBR,
 Andrey Repin (anrdaemon@freemail.ru) 27.09.2009, <16:26>

Sorry for my terrible english...

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400896

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Marc Lustig <ml...@marclustig.com>.
Looks lovely, but we use GNU sed Version 4.1.2 on Linux, and there is no -E
option available :(
Any other way to get this working?


Ryan Schmidt-60 wrote:
> 
> On Sep 26, 2009, at 14:41, Marc Lustig wrote:
> 
>> Could somebody advise me how to extract
>> aaa/bbb/tags/version
>> from
>> aaa/bbb/tags/version/xxx
>> using some bash-command like sed.
>>
>> The string before tags and after tags is arbitrary.
> 
> 
> $ echo aaa/bbb/tags/version/xxx/yyy | sed -E "s|(tags/[^/]+).*$|\1|"
> aaa/bbb/tags/version
> 
> ------------------------------------------------------
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400803
> 
> To unsubscribe from this discussion, e-mail:
> [users-unsubscribe@subversion.tigris.org].
> 
> 

-- 
View this message in context: http://www.nabble.com/implementing-pre-commit-hook-to-prevent-overwriting-files-under-tags-dir-tp25570855p25631395.html
Sent from the Subversion Users mailing list archive at Nabble.com.

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400863

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Sep 26, 2009, at 14:41, Marc Lustig wrote:

> Could somebody advise me how to extract
> aaa/bbb/tags/version
> from
> aaa/bbb/tags/version/xxx
> using some bash-command like sed.
>
> The string before tags and after tags is arbitrary.


$ echo aaa/bbb/tags/version/xxx/yyy | sed -E "s|(tags/[^/]+).*$|\1|"
aaa/bbb/tags/version

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400803

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

RE: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Marc Lustig <ml...@marclustig.com>.
Could somebody advise me how to extract 
aaa/bbb/tags/version
from 
aaa/bbb/tags/version/xxx
using some bash-command like sed.

The string before tags and after tags is arbitrary.
I need this in order to check with svnlook if this version under tags
already exists in the repo.



Marc Lustig wrote:
> 
> You are right, of course. It's so obvious....
> I will try to simplify the logic...
> thanks, guys.
> 
> 
> Johan Corveleyn wrote:
>> 
>>> Van: Marc Lustig [mailto:ml@marclustig.com]
>>> 
>>> TAGS_REGEX='tags/[^/]\+'
>>> # Get list of transactions in the 'tag' directory
>>> TAGS_CHANGES=`"$SVNLOOK" changed -t "$TXN" "$REPOS" 2>/dev/null | \
>>>                  awk '{ print $2; }' 2>/dev/null | \
>>>                  grep ^tags/ 2>/dev/null | \
>>>                  sed -e "s!^\($TAGS_REGEX\).*!\1!" | \
>>>                  sort | \
>>>                  uniq`
>>> 
>>> 
>>> I figured out, when I commit a file, the variable TAGS_CHANGES is
>>> empty.
>>> 
>>> The command
>>> $SVNLOOK" changed -t "$TXN" "$REPOS"
>>> prints out the list of committed files properly. LIke
>>> U project/tags/1.1.1/file.xml
>> 
>> It's the grep part of the command: "grep ^tags/" will not match
>> "project/tags/...". It only matches if "tags" is at the very beginning of
>> the line (because "^" matches beginning of line).
>> 
>> So I guess that snippet only works for repositories that have "tags" at
>> the root of the repository, and not below individual project folders...
>> 
>> Johan
>> 
>> ------------------------------------------------------
>> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400186
>> 
>> To unsubscribe from this discussion, e-mail:
>> [users-unsubscribe@subversion.tigris.org].
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/implementing-pre-commit-hook-to-prevent-overwriting-files-under-tags-dir-tp25570855p25628231.html
Sent from the Subversion Users mailing list archive at Nabble.com.

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400781

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

RE: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Marc Lustig <ml...@marclustig.com>.
You are right, of course. It's so obvious....
I will try to simplify the logic...
thanks, guys.


Johan Corveleyn wrote:
> 
>> Van: Marc Lustig [mailto:ml@marclustig.com]
>> 
>> TAGS_REGEX='tags/[^/]\+'
>> # Get list of transactions in the 'tag' directory
>> TAGS_CHANGES=`"$SVNLOOK" changed -t "$TXN" "$REPOS" 2>/dev/null | \
>>                  awk '{ print $2; }' 2>/dev/null | \
>>                  grep ^tags/ 2>/dev/null | \
>>                  sed -e "s!^\($TAGS_REGEX\).*!\1!" | \
>>                  sort | \
>>                  uniq`
>> 
>> 
>> I figured out, when I commit a file, the variable TAGS_CHANGES is
>> empty.
>> 
>> The command
>> $SVNLOOK" changed -t "$TXN" "$REPOS"
>> prints out the list of committed files properly. LIke
>> U project/tags/1.1.1/file.xml
> 
> It's the grep part of the command: "grep ^tags/" will not match
> "project/tags/...". It only matches if "tags" is at the very beginning of
> the line (because "^" matches beginning of line).
> 
> So I guess that snippet only works for repositories that have "tags" at
> the root of the repository, and not below individual project folders...
> 
> Johan
> 
> ------------------------------------------------------
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400186
> 
> To unsubscribe from this discussion, e-mail:
> [users-unsubscribe@subversion.tigris.org].
> 
> 

-- 
View this message in context: http://www.nabble.com/implementing-pre-commit-hook-to-prevent-overwriting-files-under-tags-dir-tp25570855p25610614.html
Sent from the Subversion Users mailing list archive at Nabble.com.

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400201

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

RE: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Johan Corveleyn <jo...@uz.kuleuven.ac.be>.
> Van: Marc Lustig [mailto:ml@marclustig.com]
> 
> TAGS_REGEX='tags/[^/]\+'
> # Get list of transactions in the 'tag' directory
> TAGS_CHANGES=`"$SVNLOOK" changed -t "$TXN" "$REPOS" 2>/dev/null | \
>                  awk '{ print $2; }' 2>/dev/null | \
>                  grep ^tags/ 2>/dev/null | \
>                  sed -e "s!^\($TAGS_REGEX\).*!\1!" | \
>                  sort | \
>                  uniq`
> 
> 
> I figured out, when I commit a file, the variable TAGS_CHANGES is
> empty.
> 
> The command
> $SVNLOOK" changed -t "$TXN" "$REPOS"
> prints out the list of committed files properly. LIke
> U project/tags/1.1.1/file.xml

It's the grep part of the command: "grep ^tags/" will not match "project/tags/...". It only matches if "tags" is at the very beginning of the line (because "^" matches beginning of line).

So I guess that snippet only works for repositories that have "tags" at the root of the repository, and not below individual project folders...

Johan

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400186

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Marc Lustig <ml...@marclustig.com>.
After getting the pre-commit script to run, I noticed that the logic is not
working as expected.

When I try committing a change of a file that resides under tags, the script
should identify that, output an error-message and exit with code 1. But this
doesn't work.

Here is the relevant snippet:

TAGS_REGEX='tags/[^/]\+'
# Get list of transactions in the 'tag' directory
TAGS_CHANGES=`"$SVNLOOK" changed -t "$TXN" "$REPOS" 2>/dev/null | \
                 awk '{ print $2; }' 2>/dev/null | \
                 grep ^tags/ 2>/dev/null | \
                 sed -e "s!^\($TAGS_REGEX\).*!\1!" | \
                 sort | \
                 uniq`


I figured out, when I commit a file, the variable TAGS_CHANGES is empty.

The command 
$SVNLOOK" changed -t "$TXN" "$REPOS" 
prints out the list of committed files properly. LIke
U project/tags/1.1.1/file.xml

The bug must be somewhere else.

-- 
View this message in context: http://www.nabble.com/implementing-pre-commit-hook-to-prevent-overwriting-files-under-tags-dir-tp25570855p25609076.html
Sent from the Subversion Users mailing list archive at Nabble.com.

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400152

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Marc Lustig <ml...@marclustig.com>.
That hint made me realize that the scripts needs to have execute-permissions.
After granting it, I get the message and the exit code is 1 as expected.
Solved.



Stein Somers wrote:
> 
> What happens if you execute the script yourself? In the hooks directory,
> do:
> 
> 	./pre-commit
> 
> -- 
> Stein
> 
> ------------------------------------------------------
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2399294
> 
> To unsubscribe from this discussion, e-mail:
> [users-unsubscribe@subversion.tigris.org].
> 
> 

-- 
View this message in context: http://www.nabble.com/implementing-pre-commit-hook-to-prevent-overwriting-files-under-tags-dir-tp25570855p25608203.html
Sent from the Subversion Users mailing list archive at Nabble.com.

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400122

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Stein Somers <ss...@opnet.com>.
What happens if you execute the script yourself? In the hooks directory, do:

	./pre-commit

-- 
Stein

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2399294

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Marc Lustig <ml...@marclustig.com>.
Thanks much for this useful hint.
It was already set to fileformat=unix.
I must be some other reason that is causing the issue.


David Weintraub wrote:
> 
> Are you on Linux? Do you know the VI (VIM) editor?
> 
> Open the hook script in "vi" and then type:
> 
> *:set ff?*
> 
> as the ex command. This will tell you whether your line endings are set to
> "dos" or "unix".
> 
> If it says your line endings are in "dos", then type:
> 
> *:set ff=unix
> 
> *and then save the hook. You can also try the *dos2unix* command on the
> hook
> script.
> 
> On Thu, Sep 24, 2009 at 11:24 AM, Marc Lustig <ml...@marclustig.com> wrote:
> 
>> thanks for the hint.
>> but how do "correct line endings" look like?
>>
>> 2009/9/24 Andrey Repin <an...@freemail.ru>:
>>  > Greetings, Marc Lustig!
>> >
>> >> I found a script in the svn.collab.net repo that is supposed to
>> prevent
>> >> overwriting content under the tags-dir.
>> >> Since this script is enabled, any commit fails with exit code 255,
>> like:
>> >
>> >>>Some of selected resources were not committed.
>> >>>A repository hook failed
>> >>>svn: Commit failed (details follow):
>> >>>svn: Ubertragen wird durch Aktion pre-commit behindert (Exit-Code 255)
>> ohne
>> >> Ausgabe.
>> >
>> >
>> >> The strange thing is, there is no single "exit 255" command in the
>> script.
>> >
>> >> To debug this, I simply used the following lines in the script:
>> >
>> >> echo "starting script" >&2
>> >> exit 1
>> >
>> >> But still, the commit-operation fails WITHOUT the message "starting
>> script"
>> >> and with exit-code 255 instead of exit-code 1.
>> >
>> >> The script has permissions 644 and is owned by root.
>> >> The installation is collabnet-rpm-package 1.5.2.
>> >
>> >> Any idea what is going wrong?
>> >
>> > This (very similar) issue has been posted just recently.
>> > Check that you have correct line endings in your script.
>> >
>> >
>> > --
>> > WBR,
>> >  Andrey Repin (anrdaemon@freemail.ru) 24.09.2009, <19:07>
>> >
>> > Sorry for my terrible english...
>> >
>> >
>>
>> ------------------------------------------------------
>>
>> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2399334
>>
>> To unsubscribe from this discussion, e-mail: [
>> users-unsubscribe@subversion.tigris.org].
>>
> 
> 
> 
> -- 
> David Weintraub
> qazwart@gmail.com
> 
> ------------------------------------------------------
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2399395
> 
> To unsubscribe from this discussion, e-mail:
> [users-unsubscribe@subversion.tigris.org].
> 

-- 
View this message in context: http://www.nabble.com/implementing-pre-commit-hook-to-prevent-overwriting-files-under-tags-dir-tp25570855p25608170.html
Sent from the Subversion Users mailing list archive at Nabble.com.

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2400120

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by David Weintraub <qa...@gmail.com>.
Are you on Linux? Do you know the VI (VIM) editor?

Open the hook script in "vi" and then type:

*:set ff?*

as the ex command. This will tell you whether your line endings are set to
"dos" or "unix".

If it says your line endings are in "dos", then type:

*:set ff=unix

*and then save the hook. You can also try the *dos2unix* command on the hook
script.

On Thu, Sep 24, 2009 at 11:24 AM, Marc Lustig <ml...@marclustig.com> wrote:

> thanks for the hint.
> but how do "correct line endings" look like?
>
> 2009/9/24 Andrey Repin <an...@freemail.ru>:
>  > Greetings, Marc Lustig!
> >
> >> I found a script in the svn.collab.net repo that is supposed to prevent
> >> overwriting content under the tags-dir.
> >> Since this script is enabled, any commit fails with exit code 255, like:
> >
> >>>Some of selected resources were not committed.
> >>>A repository hook failed
> >>>svn: Commit failed (details follow):
> >>>svn: Ubertragen wird durch Aktion pre-commit behindert (Exit-Code 255)
> ohne
> >> Ausgabe.
> >
> >
> >> The strange thing is, there is no single "exit 255" command in the
> script.
> >
> >> To debug this, I simply used the following lines in the script:
> >
> >> echo "starting script" >&2
> >> exit 1
> >
> >> But still, the commit-operation fails WITHOUT the message "starting
> script"
> >> and with exit-code 255 instead of exit-code 1.
> >
> >> The script has permissions 644 and is owned by root.
> >> The installation is collabnet-rpm-package 1.5.2.
> >
> >> Any idea what is going wrong?
> >
> > This (very similar) issue has been posted just recently.
> > Check that you have correct line endings in your script.
> >
> >
> > --
> > WBR,
> >  Andrey Repin (anrdaemon@freemail.ru) 24.09.2009, <19:07>
> >
> > Sorry for my terrible english...
> >
> >
>
> ------------------------------------------------------
>
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2399334
>
> To unsubscribe from this discussion, e-mail: [
> users-unsubscribe@subversion.tigris.org].
>



-- 
David Weintraub
qazwart@gmail.com

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2399395

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Marc Lustig <ml...@marclustig.com>.
thanks for the hint.
but how do "correct line endings" look like?

2009/9/24 Andrey Repin <an...@freemail.ru>:
> Greetings, Marc Lustig!
>
>> I found a script in the svn.collab.net repo that is supposed to prevent
>> overwriting content under the tags-dir.
>> Since this script is enabled, any commit fails with exit code 255, like:
>
>>>Some of selected resources were not committed.
>>>A repository hook failed
>>>svn: Commit failed (details follow):
>>>svn: Ubertragen wird durch Aktion pre-commit behindert (Exit-Code 255) ohne
>> Ausgabe.
>
>
>> The strange thing is, there is no single "exit 255" command in the script.
>
>> To debug this, I simply used the following lines in the script:
>
>> echo "starting script" >&2
>> exit 1
>
>> But still, the commit-operation fails WITHOUT the message "starting script"
>> and with exit-code 255 instead of exit-code 1.
>
>> The script has permissions 644 and is owned by root.
>> The installation is collabnet-rpm-package 1.5.2.
>
>> Any idea what is going wrong?
>
> This (very similar) issue has been posted just recently.
> Check that you have correct line endings in your script.
>
>
> --
> WBR,
>  Andrey Repin (anrdaemon@freemail.ru) 24.09.2009, <19:07>
>
> Sorry for my terrible english...
>
>

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2399334

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].

Re: implementing pre-commit-hook to prevent overwriting files under tags-dir

Posted by Andrey Repin <an...@freemail.ru>.
Greetings, Marc Lustig!

> I found a script in the svn.collab.net repo that is supposed to prevent
> overwriting content under the tags-dir.
> Since this script is enabled, any commit fails with exit code 255, like:

>>Some of selected resources were not committed.
>>A repository hook failed
>>svn: Commit failed (details follow):
>>svn: Ubertragen wird durch Aktion pre-commit behindert (Exit-Code 255) ohne
> Ausgabe. 


> The strange thing is, there is no single "exit 255" command in the script.

> To debug this, I simply used the following lines in the script:

> echo "starting script" >&2
> exit 1

> But still, the commit-operation fails WITHOUT the message "starting script"
> and with exit-code 255 instead of exit-code 1.

> The script has permissions 644 and is owned by root.
> The installation is collabnet-rpm-package 1.5.2.

> Any idea what is going wrong?

This (very similar) issue has been posted just recently.
Check that you have correct line endings in your script.


--
WBR,
 Andrey Repin (anrdaemon@freemail.ru) 24.09.2009, <19:07>

Sorry for my terrible english...

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2399316

To unsubscribe from this discussion, e-mail: [users-unsubscribe@subversion.tigris.org].