post commit hook to update a file under version

旧巷老猫 提交于 2019-12-01 01:47:03

问题


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. But i dont know what command can do that. I know i have this params:

#!/bin/sh

REPOS = "$1"
REV = "$2" 

But how can i replace the content of that file without making a new revision ? and still have those changes in my repo ?

UPDATE: Since maybe i havent been clear i will try a more detailed explination: Lets say i have this repo: /svn/repos/project/trunk/ and in it i have a file called version.ini that is under version control. What i want to do is that on every commit update that file to the new revision. Lets say that the current revision is 263 i want that file to have 263 writen in it. And to respond to an answer bellow you cant use keywords since they only work if i update that file and i dont want to do it.

Hope i made sense, and thanks for any help given. Cheers


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/650168/post-commit-hook-to-update-a-file-under-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!