Precommit hook for svn to modify files to be committed in c#

假装没事ソ 提交于 2019-12-05 01:03:02

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/2234606/precommit-hook-for-svn-to-modify-files-to-be-committed-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!