Question

I am writing a pre-commit hook in Java. The pre-commit hook (batch file) calls my Java program with parameters: repositoryLocation, transactionId. I need to validate XML files during the commit and if any of them seems to be invalid, I am returning a non-zero exit code back to my pre-commit hook, and then the entire commit transaction is rolled back.

I can access the contents code here of any revision of the file the following way:

SVNRepository repository = ...;
SVNProperties fileProperties = new SVNProperties();
ByteArrayOutputStream baos = new ByteArrayOutputStream( );

repository.getFile( changeEntry.getCopyFromPath() , revisionNum , fileProperties , baos );
log.debug("<![CDATA["+baos.toString()+"]]>");

BUT I am unable to access the content of the file being uploaded (content of the working copy, committed by the user). I do not want to write anything to SVN, I need to read the uploaded file(s)'s content and then do some validation. Commit or rollback will be done by the SVN just after my Java program finishes.

Can anybody help me with this problem?

Was it helpful?

Solution

Inside bat-file of hook you can use svnlook changed ... on order to get list of files in transaction and for filenames from changed command - svnlook cat ... FILENAME in order to get content of file in stdout

OTHER TIPS

Thanks to Lazy Badger's and one of my colleague's advices, i just found out that

SVNLOOK CAT repoPath -t txn

is the command I need to reinvent, so by looking at

org.tmatesoft.svn.core.wc.admin.SVNLookClient.doCat(File repositoryRoot, String path, String transactionName, OutputStream out) throws SVNException

function, I can get the necessary output streams & do the rest of the trick ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top