How to use pre-commit hook(Windows batch file) for a particular folder in SVN?

StackOverflow https://stackoverflow.com/questions/9532050

  •  03-12-2019
  •  | 
  •  

Вопрос

I want to create a pre-commit hook in SVN (i.e. .bat file for Windows) that checks for empty log messages. Moreover, I want to target this check only for a particular folder in SVN.

Can anybody help regarding the same?

Regards, Ruhee Jaiswal

Это было полезно?

Решение

If you're fine with TortoiseSVN, you could enter a client-side hook there.

TortoiseSVN passes the following parameters to the pre-commit hook:

PATH DEPTH MESSAGEFILE CWD

where the interesting one is PATH:

PATH
A path to a temporary file which contains all the paths for which the operation was started. Each path is on a separate line in the temp file.

So, when your hook is called (could be in any language btw), do the following steps:

  1. check the content of MESSAGEFILE. If there's a comment inside, everything is fine, return successful from the script (I don't remember whether success is indicated by 0 or !0, just give it a try)
  2. if the MESSAGEFILE is empty, browse through the file PATH and see if there are affected elements in that. If so, return an error; otherwise return success.

Другие советы

I would recommend using a svn property for this if you're on Windows and using TortoiseSVN.

tsvn:logminsize sets the minimum length of a log message for a commit. If you enter a shorter message than specified here, the commit is disabled. This feature is very useful for reminding you to supply a proper descriptive message for every commit. If this property is not set, or the value is zero, empty log messages are allowed.

Also make sure to check out the other features like bug tracker integration.

If you'd really like to do this on the server side using a hook you can try this, in which case your question is a duplicate :)

  1. You can't have hooks, which works on event only for some subtree
  2. Hooks are handlers for repository-wide events
  3. If you want check only for some parts of affected repo, you must add logic inside hook-code

In addition to this answer Windows Pre-commit hook for comment length Subversion you can use svnlook dir-changed to check for specific directories of the current commit.

So you could add something like

svnlook dir-changed %REPOS% -t %TXN% | findstr your_path > nul
 if %errorlevel% equ 0 exit 0

svnlook log %REPOS% -t %TXN% | findstr . > nul  
 if %errorlevel% gtr 0 (goto err) else exit 0  
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top