post commit hook to update a file under version

后端 未结 2 987
無奈伤痛
無奈伤痛 2021-01-12 06:08

I have made a file called version.ini that is under version control (/trunk/version.ini) i now wanted to make a post commit hook to update that file with the latest version

相关标签:
2条回答
  • 2021-01-12 06:29

    What you actually want is not a way to modify your commits, but something like svn:keywords. Unfortunately, as you can read in the box "Where's $GlobalRev$?" this doesn't really do what you want. Instead, you'll have to write a script to call and parse the output of svnversion and somehow put the result in your files as part of the build.

    Now, to answer your literal question it's still fun to think about what you can and cannot do in svn hook scripts:

    You can't change a commit from a post-commit hook

    By the time post-commit hook runs, the commit has already been finalized (as the name implies) so changing files is out of the question. You can only inspect the changes at this point.

    You can't modify pending commits from a pre-commit hook either

    You can examine the content of a pending transaction from a pre-commit hook by using the svnlook tool with the --transaction switch, but you can't change it.

    If arbitrary changes could be made in a pre-commit hook, then obviously the server would need to report back these changes to the svn client. Otherwise the client would think his files are at the committed revision, while they are actually different. If the svn client would accept such reported changes it would lead to the possibility of your work being wiped out by a commit. That would be a surprising feature to have for a version control system, to put it mildly. Needless to say subversion does not allow this.

    0 讨论(0)
  • 2021-01-12 06:33

    There is no way to change anything in the repo without modifying the revision number.

    The solution is to put special keywords (search for svn:keywords) into the file and have SVN replace them during checkout. It will seem that these values come from the repository but the representation of the file in the repository will not change.

    You're probably looking for $LastChangedRevision$ (or $Rev$ for short).

    Another solution is to add a rule to your build tool/Makefile/whatever which uses svn info on the root directory of your project to determine the current revision and puts that into a temporary file (which is not added to your repo).

    0 讨论(0)
提交回复
热议问题