简体   繁体   中英

How to write a SVN pre-commit hook script in Windows(Server-side)

Each change made and committed to SVN by a developer on my team delivers a requirement of the app and this requirement has an id which is written in the first line of the commit message.

I need a hook to catch this id and call an external service to verify if the id status is OK. I have read a lot about SVN structure and hooks but don´t understand how to write this hook in Java.

A hook is is just a executable program placed in a specific place that accepts specific arguments. What language it is in doesn't really matter.

In your case if you're trying to write it in Java and run it on Windows you probably need to write a .bat file and install it as under the hooks directory with the proper name. You'll need to pass through the arguments the batch file receives to your java program.

The reason you'll need a batch file here is because Windows can't just start a Java program for you and you need to run Java with the proper arguments.

Something like this should work: @echo off java -jar myjavahook.jar %*

The %* copies all the arguments to the batch file and adds them to your java program.

You may need different or additional arguments depending on your Java program.

Since you're writing a pre-commit hook and the exit code of the batch file is important you'll probably also want to do something like this what is described in this other question: Can a batch file capture the exit codes of the commands it is invoking?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM