Write current svn version to text file

I have a website with rails. I would like to restart mongrel to write the current version of svn to public / version.txt so that I can then put this in a comment in the page title.

The problem is getting the current local version of svn - I'm a little confused.

If, for example, I update svn in a file that has not been updated after some time, I get "In revision 4571.". However, if I do svn info, I get

Way:.
URL: http: //my.url/trunk
Repository root: http: //my.url/lesson_planner
UUID repository: #########
View: 4570
Node View: Catalog
Schedule: normal
Last edited by: max
Last modified: 4570
Last Modified Date: 2009-11-30 17:14:52 +0000 (Mon, Nov 30, 2009)

Please note that this indicates a revision of version 4570, 1 below the previous one.

Can someone set me up directly and show me how easy it is to get the current version number?

thanks max

+6
svn ruby-on-rails
source share
5 answers

Subversion comes with a command to do just that: SVNVERSION.EXE .

Usage: svnversion [OPTIONS] [WC_PATH [TRAIL_URL]]

Generate a compact version number for the WC_PATH copy work path. TRAIL_URL is the end of the URL used to determine if WC_PATH itself is enabled (detecting switches inside WC_PATH is not supposed to be TRAIL_URL). The version number is written to standard output. For example:

$ svnversion . /repos/svn/trunk 4168 

The version number will be one number if the working copy is a single revision, has not been changed, and has not been switched from a URL that matches the TRAIL_URL argument. If the copy is unusual, the version number will be more complex:

4123: 4168 mixed audit working copy
4168M modified working copy
4123S changed working copy
4123: 4168MS mixed revision, modified, removable working copy

If it is called in a directory that is not a working copy, the exported directory says that the program will output 'exported'.

If called without arguments, WC_PATH will be the current directory.

Valid parameters: -n [--no-newline]: do not output the final new line -c [--committed]: last change, not current versions -h [--help]: display this help --version: show information about version

+6
source share

I use the following script shell fragment to create the svnversion.h header svnversion.h , which defines a few constant character strings that I use in the compiled code. You should have something very similar:

 #!/bin/sh -e svnversion() { svnrevision=`LC_ALL=C svn info | awk '/^Revision:/ {print $2}'` svndate=`LC_ALL=C svn info | awk '/^Last Changed Date:/ {print $4,$5}'` now=`date` cat <<EOF > svnversion.h // Do not edit! This file was autogenerated // by $0 // on $now // // svnrevision and svndate are as reported by svn at that point in time, // compiledate and compiletime are being filled gcc at compilation #include <stdlib.h> static const char* svnrevision = "$svnrevision"; static const char* svndate = "$svndate"; static const char* compiletime = __TIME__; static const char* compiledate = __DATE__; EOF } test -f svnversion.h || svnversion 

It is assumed that you delete the created header file in order to invoke the assembly of a new one.

+4
source share

If you just want to print the latest version of the repository, you can use something like this:

 svn info <repository_url> -rHEAD | grep '^Revision: ' | awk '{print $2}' 

You can use capistrano for deployment, it creates a REVISION file that you can copy to public / version.txt

+2
source share

It seems that you are using svn info in the directory, but svn update for a specific file. If you upgrade the catalog to version 4571, svn info should print:

Way:.

URL: http: //my.url/trunk

Repository root: http: //my.url/lesson%5Fplanner

UUID repository: #########

View: 4571

[...]

Last modified: 4571

Note that the โ€œlast modified revisionโ€ does not necessarily match the latest version of the repository.

+1
source share

Thanks to everyone who suggested capistrano and svninfo.

We really use capistrano, and it really makes this REVISION file, which, I think, I saw before, but did not pay attention to it. However, this is not exactly what I need, because it is updated only during deployment, while sometimes we can secretly update a couple of files and then restart, and not perform a full deployment.

I finished my own file using svninfo, grep and awk, as many people suggested here, and published it in public. This is created when you start mongrel, which is part of the deployment process, and the restart process, therefore, is performed both times.

Thanks everyone!

0
source share

All Articles