Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to apply some styling to code whenever someone commits to an SVN repository, for this I use astyle on the commited changes with an svn pre-commit hook.

I can get the file names like this, but when I apply astyle, it seems the program cannot get the data from within the files:

for FILE in $($SVNLOOK changed -t "$TXN" "$REPOS" | cut -b 5-); do 
        # echo $REPOS/$FILE 1>&2             # prints the files' paths
        astyle --style=gnu -n $FILE
done

# commit the changes from astyle here

Any idea how can I achieve this?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I'm afraid, but I have bad new for you: you can't do it

As mentioned in SVN-Book in "Implementing Repository Hooks" chapter, in comment with Stop-Sign (you know, that it means)

While hook scripts can do almost anything, there is one dimension in which hook script authors should show restraint: do not modify a commit transaction using hook scripts. While it might be tempting to use hook scripts to automatically correct errors, shortcomings, or policy violations present in the files being committed, doing so can cause problems. Subversion keeps client-side caches of certain bits of repository data, and if you change a commit transaction in this way, those caches become indetectably stale. This inconsistency can lead to surprising and unexpected behavior. Instead of modifying the transaction, you should simply validate the transaction in the pre-commit hook and reject the commit if it does not meet the desired requirements. As a bonus, your users will learn the value of careful, compliance-minded work habits.

Jack Repenning, Chief Technology Officer from CollabNet, also mention this

... sadly I must tell you that no, you can't do that. The file content for the files being committed is available to you within the hook script (through svnlook's "changed" and "cat" commands), but what you see is a copy of the data that has already been entered into the database (although not actually committed yet), and you have no facility to modify that, only to allow or refuse the final transaction commit.

If you still brave to try, you can try to understand code from rather old topic (year 2009), where author claims "it modify transaction content"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.