how to get projectname in pre-commit hook

124 views
Skip to first unread message

Chad Cedotal

unread,
Sep 20, 2023, 12:04:09 PM9/20/23
to TortoiseSVN
Sorry if I'm asking a basic question.  I'm new to SVN. 

We've just moved our backend repository from CVS to SVN.  We've implemented a pre-commit hook that we use to validate the commit request.  To perform this validation, the project name is required, which in SVN looks like the root folder.  The guy that implemented the pre-commit hook has told me that he hasn't found a way to obtain this piece of information from within the pre-commit hook, and doesn't find it as a passed in value.  So the pre-commit hook is coded to expect the first word of the Comment as the project name which get's parsed out.  This works but places the burden on the developer, and is a step backwards from what we had with CVS.  

Can someone point us in the right direction?

Stefan

unread,
Sep 20, 2023, 1:30:35 PM9/20/23
to TortoiseSVN
First, are you talking about client-side hooks (https://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-settings.html#tsvn-dug-settings-hooks) or server side hooks (https://svnbook.red-bean.com/en/1.8/svn.ref.reposhooks.pre-commit.html)?

For client-side hooks, you get the CWD of the working copy, which you can then use to get the repo url or other info via e.g. the command line client or SubWCRev.
For server side hooks, you get the path to the repository, which you then can pass to the svnlook utility to get all the info you need.

Chad Cedotal

unread,
Sep 21, 2023, 11:30:49 AM9/21/23
to TortoiseSVN
Our guy said he's aware of svnlook, so we may need a little guidance.  Would you be able to provide an example?  

Daniel Sahlberg

unread,
Sep 21, 2023, 11:43:52 AM9/21/23
to TortoiseSVN
What is a "project name" in your setup?

I assume you have read the Subversion book and particularly the section on planning your repository layout [1]. Since you make a distinction between "project name" and "root folder", I assume you have gone with the "one repository multiple projects" model.

Google gave me an example on StackOverflow [2] there is an example on how to use svnlook to check for the changed paths and assuming the project name is part of the path it should be fairly easy to parse.

Please bear in mind that with the "one repository multiple projects" model there is no guarantee that a single commit will only touch files within one "project"; it would be trivial to check out a working copy containing the repository root and changing several projects in one commit. This has to be accounted for in the pre-commit hook script.

Kind regards,
Daniel
Reply all
Reply to author
Forward
0 new messages