Posted in Howto Linux Versioning

Subversion : automating svn:keywords

January 11, 2007 - 17 comments

We’ll see here how you can automate the addition of SVN keywords to your newly added or imported file in your Subversion repository.

Changes are being made on the client computer, NOT the repository. It means you need to apply the following to every computer accessing the SVN repository.

For files already in the repository, you will need to manually set the keywords this way :
svn propset svn:keywords "Id" file.sh

To set scripts as executable :
svn propset svn:executable ON file.sh

1. Enabling auto properties

Edit ~/.subversion/config

Under the miscellany section, set enable-auto-props to yes

[miscellany]
enable-auto-props = yes

Then, you should find an auto-prop section :

[auto-props]
### The format of the entries is:
### file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?'). All entries which match will be applied to the file.
### Note that auto-props functionality must be enabled, which
### is typically done by setting the 'enable-auto-props' option.
# *.c = svn:eol-style=native
# *.cpp = svn:eol-style=native
# *.h = svn:eol-style=native
# *.dsp = svn:eol-style=CRLF
# *.dsw = svn:eol-style=CRLF
# *.sh = svn:eol-style=native;svn:executable
# *.txt = svn:eol-style=native
# *.png = svn:mime-type=image/png
# *.jpg = svn:mime-type=image/jpeg
# Makefile = svn:eol-style=native

If I wanted to have the “Id” keyword automatically added to *.sh files, I’d uncomment the *.sh line and add the keyword values, so it’d look like this :
*.sh = svn:eol-style=native;svn:executable;svn:keywords=Id

2. Editing your files

Just put somewhere in your bash script the “$Id$” keyword, add and commit :

$ vi test.sh

#!/bin/bash
# SVN : $Id$
echo "This is a test"

Add and commit :
$ svn add test.sh
A test.sh
$ svn commit -m “Testing auto keywords”
Sending test.sh
Transmitting file data .vi
Committed revision 30.

Once commited, the file would look like this :

#!/bin/bash
# SVN : $Id: test.sh 30 2007-01-10 23:34:59Z user $
echo "This is a test"

3. Verifying the properties of a file :

If you want to check out the properties set on a file, just do :
$ svn proplist test.sh
Properties on ‘test.sh’:
svn:executable
svn:keywords
svn:eol-style

If you want to check out the keywords set on that file :
$ svn proplist test.sh -v
Properties on ‘test.sh’:
svn:executable : *
svn:keywords : Id
svn:eol-style : native

Comments

Roberto PRESEDO

January 21, 2007 - 15:13

Sorry, but I can’t find the ~/.subversion/config file… Where is it ? in the repository or in the Subversion folders

Pryonic

January 23, 2008 - 17:27

It seems that is has to be set on the client machine rather than the server. This mean it must be set for each user on each client, rather than on the server which severly limits its use.

Johannes Egger

January 29, 2008 - 19:10

It does indeed severely limit its use. Also, the RedHat Certified Engineer link is messed up :-)

Sébastien Wains

January 29, 2008 - 23:22

Hi Johannes,

I fixed the article, I’m now making it clear the changes must be set on every client machines. If you are aware of any way to enable auto keywords from the repository, feel free drop a comment.

Also, the RHCE link is fixed, thanks a lot for the notice. Apparently they changed the way they process the links to the “certification central”.

Cheers
Seb

Johannes Egger

January 29, 2008 - 23:48

Re: Redhat – yes, I thought that might be the case. Apologies for not contacting you privately (lazyness).

Concerning subversion: this issue is somewhat related: http://subversion.tigris.org/issues/show_bug.cgi?id=1974

I can’t help but wonder whether one could actually set properties using the post-commit hook?

Heike

May 26, 2008 - 1:56

Hi Sébastien,

I found your SVN information quite useful. Thanks a lot for providing it!
Additional to adding svn keywords like author, revision, etc. to my source files, I would like to add all the log messages. It doesn’t seem as simple as adding keywords. Do you know whether it’s possible to add log messages to source files and if so, how?
Thanks again!
Cheers, heike.

Sébastien Wains

May 26, 2008 - 19:03

Hi Heike,

This is not possible to my knowledge.
The official SVN guide doesn’t mention anything relevant as well.. http://svnbook.red-bean.com/en/1.1/ch07s02.html

Heike

May 26, 2008 - 21:21

Hi Sébastien,
hmm, I know it works with CVS and that’s why I was hoping it’s also possible with SVN; but obviously not. Anyway, thank you once more!
Cheers, heike.

Omurhan Akdemir

September 23, 2008 - 8:05

Roberto,

Guess you are working on windows.
It’s under c:\Documents and Settings\User\application data\Subversion

Cheers
omurhan

Josh

September 25, 2008 - 4:24

Yay! Thank you for this! I looked all over to find out how to do automatic revision numbers and dates.

mk

April 1, 2009 - 16:37

Hi,

I’m a SVN newbie.

I followed what you’ve mentioned above to get the following bit in my .CS file show the expected bit

/********************************************
* Revision: $Revision$
* LastChangedDate: $Date$
* LastChangedBy: $Author$
*********************************************/

tried to run ‘$ svn proplist XXX.cs’ but it shows ‘.’ is not an working folder.

what am I missing?

mk

April 1, 2009 - 16:41

forgot to add the entry at .subversion/config

*.aspx.cs = svn:eol-style=native;svn:keywords=Author Date Revision

mk

April 1, 2009 - 16:41

I meant this is my entry at that file…

Still no luck

Sebastien Wains

April 1, 2009 - 23:07

can you run svn info in the directory where the .cs file resides, and give me the output ?

mk

April 2, 2009 - 11:18

Hi Sebastian,

appreciate your kind response.

when I run ’svn info’ command in the repository directory (at repo server) all I get ” ‘.’ is not an working copy”. This makes me wonder whether I should be running that commnd at my dev machine, local working copy.

I’ve got only TortoiseSVN subversion client installed in dev machine. Do I need to install a full blown SVN in my machine? not sure…

Bit lost here.

thanks in advance..

MK

PS Repo server has got Visual SVN

mk

April 2, 2009 - 11:29

Hi,

I may have found the solution in the TSVN’s user manual…

thank you anyway…

MK

Khalid

July 31, 2009 - 18:07

If you manage a repository and want this to happen automatically, then here is a way to make subversion/svn recognize CVS Id and Revision tags centrally, without doing any client-side changes.

Leave Comment

Please consider visiting the partners below if you enjoyed this article :

If this post saved you time and money, please consider checking my Amazon wishlist.

Before submitting, some rules :
- Is your comment related to the article ?
- You're having a problem ? Have you checked Google, other howtos, docs, manpages ?
- You're still having the problem ? Have you raised log verbosity, checked traces, ran tcpdump ?
- Have you checked your configuratoin for typo ?
Unless your comment is providing additional info or respect the rules above, DON'T comment.
If you don't understand what you are doing, I urge you to read the documentation, I'm not your free Level 1 helpdesk guy.