tags:

views:

529

answers:

4

I want to modify in certain way(Actually format the files in a code formatter) before they are committed to repository. I have found out from Precommit example (Use guest as name and no password) how to write in python.But what i want to know is how to get list of files to be committed and other command line arguments this one takes.One more thing i prefer is to write my own pre commit hook in C# rather than Python or any other script.

Few points I will write a exe which will format,but i want the list of files being committed How to configure this with svn.

A: 

First of all, I think this is a bad idea. Why would you want to change code before a commit? in my opinion it's much better to check for code formatting/standards violations and abort the commit. I would be very frustrated if my code was changed during a commit.

To answer your specific question, use svnlook changed to get the list of changed files. svnlook dirs-changed would give you the directories affected by the pending transaction.

Sam Post
This is just to format the code style.It does not affect the contents in any other way.What i am doing is to beautify the class file.
Ravisha
svnlook won't help : he wants to use the client-side hook script feature of TSVN, not the server-side hook scripts.
Stefan
+1  A: 

As you maybe already read, a hook in subversion is just a program, called at a specifc time within the commit process with some parameters and a return value. You can place any runable program within the hook directory. So you can also place any .exe there (which can be a .Net program as well). Then check the command line arguments and do whatever you like and return any int value as errorlevel.

Within your application you can maybe use SharpSVN or anything else to get an easy access to the repository to make any checks and send the result to the user.

Oliver
+1  A: 

The first parameter passed to the pre-commit hook script is a path to a text file. That text file contains all the paths which are to be committed, separated by newlines.

But for your situation, you might better use the start-commit hook: that script is called right before the commit begins, but after the user selected the files/folders to commit. The pre-commit script is called when the commit dialog is shown, before the user starts selecting files/folders for committing.

Stefan
Wrong! Precommit is called after the user clicks on commit on selected files. start commit is called even before the UI for list of dirty files are shown svnbook.red-bean.com/nightly/en/…
Ravisha
@Ravisha: In your question you link to a CLIENT SIDE hook script, which is TortoiseSVN-specific. Somehow, I can't believe the very author of that tool would be wrong about this...
jeroenh
@ jeroenh My reply was to this statement by stefan"The pre-commit script is called when the commit dialog is shown, before the user starts selecting files/folders for committing."Which is wrong,Precommit is after user selects the files but before he clicks on OK button.Thats all i said.I am not saying anythin contradictory to Tortoise SVN docs
Ravisha
+4  A: 

Precommit hooks that modify the committed files are considered 'a bad thing':

http://svnbook.red-bean.com/en/1.5/svn.reposadmin.create.html#svn.reposadmin.create.hooks

The idea merits a big red box in the official SVN documentation, and warns that this will affect how the SVN client works with the repository in bad ways.

John McAleely