You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Kenneth Riddile <kf...@yahoo.com> on 2009/06/21 03:32:43 UTC

altering files with a pre-commit hook?

My team writes portable C/C++ that is all written with Visual Studio on Windows and is then used on both Windows and Unix.  GCC on Unix complains when files don't end in newlines while Visual Studio does not.  I already have a pre-commit hook that fails the commit when a source file doesn't end in a newline.  I was wondering if someone knows of a way to automatically append a newline to those files at pre-commit time instead of forcing the user to go and add them manually.  I won't be surprised if this can't be done since the ability to transparently modify files committed by the user could certainly be dangerous.
Thanks,Kenny Riddile

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

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

Re: altering files with a pre-commit hook?

Posted by Andrey Repin <an...@freemail.ru>.
Greetings, Kenneth Riddile!

> My team writes portable C/C++ that is all written with Visual Studio on
> Windows and is then used on both Windows and Unix.  GCC on Unix complains
> when files don't end in newlines while Visual Studio does not.  I already
> have a pre-commit hook that fails the commit when a source file doesn't end
> in a newline.
> I was wondering if someone knows of a way to automatically append a newline
> to those files at pre-commit time instead of forcing the user to go and add
> them manually.  I won't be surprised if this can't be done since the ability
> to transparently modify files committed by the

svn:eol-style property is not what you want?
Or you mentioning specifically the \n right before EOF?


--
WBR,
 Andrey Repin (anrdaemon@freemail.ru) 22.06.2009, <18:49>

Sorry for my terrible english...

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

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


Re: altering files with a pre-commit hook?

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Jun 20, 2009, at 22:32, Kenneth Riddile wrote:

> My team writes portable C/C++ that is all written with Visual  
> Studio on Windows and is then used on both Windows and Unix.  GCC  
> on Unix complains when files don't end in newlines while Visual  
> Studio does not.  I already have a pre-commit hook that fails the  
> commit when a source file doesn't end in a newline.  I was  
> wondering if someone knows of a way to automatically append a  
> newline to those files at pre-commit time instead of forcing the  
> user to go and add them manually.  I won't be surprised if this  
> can't be done since the ability to transparently modify files  
> committed by the user could certainly be dangerous.

Thou shalt not modify the transaction in the pre-commit hook. :) But  
you can, if you insist, have the hook commit a second revision  
immediately following the first to add that trailing newline if  
necessary. Your hook script might then have to maintain a working  
copy of its own in which to make such modifications. It might become  
a nontrivial script. Personally I'd just leave your pre-commit hook  
as-is, and get your developers to add the newline. My editor has a  
setting for doing this automatically when saving any file; hopefully  
the one your developers are using does too.

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

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

Re: altering files with a pre-commit hook?

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Jun 22, 2009, at 09:31, David Weintraub wrote:

> As others have stated: You don't do this because of the consequences.
> In order to do this, you have to submit a SECOND commit which means
> that the person who just did the commit will find their working
> directory out of date.
>
> Plus, there is the possibility of your second commit firing off
> another pre-commit hook which might fire off another commit which
> might fire off a third pre-commit hook all the way through all seven
> circles of hell.

Assuming the script is written correctly that shouldn't happen, since  
the purpose of the script would be to add an eol to the end of a file  
that does not already end in an eol. But definitely while you're  
writing the script you might not get it right the first time and  
could easily find yourself with a script that causes an infinite loop  
of commits. So it should definitely be developed on a temporary  
throwaway repository and not on your production repository.


> What I do is require the svn:eol-style property on certain file types
> set to what is needed. For example, all *.sh, *.pl, Makefiles, and
> other Unix files that require a <LF> line ending only, or for example,
> all the special files that VisualStudio requires a <CR><LF> ending on.
>
> The property will make sure that the file is stored with the correct
> line ending in the repository, so your developers won't have to worry
> about it. You can also let your developers know how to configure
> autoproperties, so that when a new file is created, the correct
> property is setup when the developer runs "svn add".
>
> The autoproperties will keep your developers from getting frustrated
> with the whole line ending issue.

Yes, but the issue is not the eol-style of the entire file, but the  
fact that he wants every text file to be guaranteed to end with an  
eol, which is not something the svn:eol-style property has anything  
to do with.

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

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

Re: altering files with a pre-commit hook?

Posted by David Weintraub <qa...@gmail.com>.
As others have stated: You don't do this because of the consequences.
In order to do this, you have to submit a SECOND commit which means
that the person who just did the commit will find their working
directory out of date.

Plus, there is the possibility of your second commit firing off
another pre-commit hook which might fire off another commit which
might fire off a third pre-commit hook all the way through all seven
circles of hell.

What I do is require the svn:eol-style property on certain file types
set to what is needed. For example, all *.sh, *.pl, Makefiles, and
other Unix files that require a <LF> line ending only, or for example,
all the special files that VisualStudio requires a <CR><LF> ending on.

The property will make sure that the file is stored with the correct
line ending in the repository, so your developers won't have to worry
about it. You can also let your developers know how to configure
autoproperties, so that when a new file is created, the correct
property is setup when the developer runs "svn add".

The autoproperties will keep your developers from getting frustrated
with the whole line ending issue.

On Sat, Jun 20, 2009 at 11:32 PM, Kenneth Riddile<kf...@yahoo.com> wrote:
> My team writes portable C/C++ that is all written with Visual Studio on
> Windows and is then used on both Windows and Unix.  GCC on Unix complains
> when files don't end in newlines while Visual Studio does not.  I already
> have a pre-commit hook that fails the commit when a source file doesn't end
> in a newline.  I was wondering if someone knows of a way to automatically
> append a newline to those files at pre-commit time instead of forcing the
> user to go and add them manually.  I won't be surprised if this can't be
> done since the ability to transparently modify files committed by the user
> could certainly be dangerous.
> Thanks,
> Kenny Riddile



-- 
David Weintraub
qazwart@gmail.com

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

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