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.

Ravisha
  • 3,261
  • 9
  • 39
  • 66
  • You should state in the question that you are talking about Tortoise side hook (example from link is a client side hook). – user1068352 Jan 05 '13 at 22:02

4 Answers4

10

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
  • 1,929
  • 2
  • 18
  • 35
  • 1
    It is bad, but is there a way to do this anyways? Like to allow the commit to occur (no pre-commit); on the post-commit, it checks out the files, performs the formatting, then re-checks them back in? Or to delete/strip executables from being checked in on pre-commit (I have people who aren't smart enough to know how to remove exe's from project, even with failing them and giving intelligent reply)? – TamusJRoyce Jul 26 '11 at 13:50
  • I was asking this in regards to super-large binary files. And because Obliterate does not yet exist. But I have come to realize that the file would be different after manipulating it, causing it to always be out-of-date. This would cause it to always download, even if it is the same as after (not before) it gets checked in. If there is a way around that issue, I'm still interested. – TamusJRoyce Oct 20 '11 at 18:07
  • @TamusJRoyce see my question there: http://stackoverflow.com/questions/9888667/ankhsvn-client-side-pre-commit-hook – santa Apr 03 '12 at 07:09
3

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 start-commit script is called after the user clicks OK in the commit dialog, and before the actual commit begins. This hook has a list of exactly what will be committed.

Stefan
  • 43,293
  • 10
  • 75
  • 117
  • 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 Feb 11 '10 at 03:24
  • @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 Feb 12 '10 at 11:24
  • 1
    @ 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 Feb 15 '10 at 05:10
1

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
  • 3,721
  • 3
  • 17
  • 14
  • 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 Feb 10 '10 at 08:46
  • svnlook won't help : he wants to use the client-side hook script feature of TSVN, not the server-side hook scripts. – Stefan Feb 10 '10 at 15:27
  • 1
    +1 Original question says nothing about client-side/server-side hook. And this is the only answer which tries to explain how to do it, even if it is something you don't want to do. – TamusJRoyce Jul 26 '11 at 14:00
1

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
  • 43,366
  • 8
  • 94
  • 151