Reputation: 2890
We have a PHP Project under SVN control(VisualSVN).
Somehow, i need to update a file in the repo with the current revision number. So that when the main site gets updated/checkout we can show the svn build number (this part is not the issue).
is it possible with a pre/post-commit-hook to do this?
Upvotes: 1
Views: 1188
Reputation: 28711
Sounds like you need a build solution, rather than a pre-commit hook. Using a build system like Apache Ant, you could grab the latest revision number from the repository when preparing your solution for the live environment.
Edit: To actually answer your question "is it possible with a pre/post-commit-hook to do this?" yes it is technically possible but as already suggested, it should be avoided.
Upvotes: 2
Reputation: 100
What about requiring developers to update the file themselves and then using a pre-commit script to refuse commits where the update is incorrect? Perhaps the insertion of a revision number is a responsibility better incorporated into one's editor or build process / deploy scripts.
Upvotes: 0
Reputation: 97282
While mliebelt quoted the right text, he made bad conclusion. Even twice:
Second statement
If post-commit hook will rewrite file not included in this commit, it will be perfectly valid operation, which broke nothing.
First statement
This solution is clearly bad for a lot of reasons:
Repository (or Working Copy of) per se have information about last revision in it (svn info
, svnversion
, svn log -r HEAD
), storing it inside data violates Occam's Raroz. You have only extract data, when you "publish" data for using outside repository.
Which tools and how to use is heavy-dependent from: deploy workflow, OS (you haven't gawk-grep-sed on ordinary Win-box), just some hints:
And at last
Upvotes: 0
Reputation: 15525
pre and post-commit-hooks behave differently (see the documentation in the SVN red book about the hooks and especially the part about implementing the hooks):
So no mention of the chance to change anything. Instead, there is a paragraph in the section "implementing the hooks":
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.
So I would say, it is not possible or at least recommended to do that.
Upvotes: 2