Aliaspooryorik
ColdFusion ORM Book

Keyword Substitution with TortoiseSVN

A cool feature of Subversion is that you can get it to update the comments in your script automatically when you commit it. Here is an example of the header I've got on my Application.cfc script.


<!---
=================================================================================================
Repository path:    $HeadURL: http://svnserver.com/svn/aliaspooryorik/trunk/Application.cfc $
Last committed:     $Revision: 7 $
Last changed by:    $Author: john.whish $
Last changed date:    $Date: 2009-01-07 13:15:08 +0000 (Wed, 07 Jan 2009) $
ID:            $Id: Application.cfc 7 2009-01-07 13:15:08Z john.whish $
=================================================================================================
--->

Whenever I (or anyone else) update this file and commit it, the header comment is updated. This can be particularly useful when working with other developers as you can see who made the last commit without having to do a lookup to subversion. So, how do you do it?

In your script add the following comment.


<!---
=================================================================================================
Repository path:    $HeadURL$
Last committed:     $Revision$
Last changed by:    $Author$
Last changed date:    $Date$
ID:            $Id$
=================================================================================================
--->

The values wrapped in the $ signs are reserved keywords (svn:keywords). Now you need to tell subversion to replace those values as it is not enabled by default. You can do this for a whole project or for individual files if you wish.

You can set this up using the svn propset command (more info here: http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html) or, if you are using TortoiseSVN, then follow these steps:

  1. Right click on the root folder of your working copy.
  2. Select 'properties' (Note: this is not the TortoiseSVN properties option!)
  3. Select the 'subversion' tab.
  4. Click the 'properties' button.
  5. In the new 'properties' dialog, select the 'New' button.
  6. Select 'svn:keywords' from the dropdown list.
  7. Enter (note that each one is on a new line)
    HeadURL
    Revision
    Author
    Date
    ID
  8. If you want to apply keyword substitution to all sub files and folders, tick the box titled 'Apply property recursively'
  9. Click 'OK'

That's it. It is worth pointing out that your file will only be updated when you do a commit so it won't be updated right away.

Alternatively if you are feeling brave you can set this up as the default. To do this you need to:

  1. Right click on the the root of your working copy.
  2. Select 'TortoiseSVN -> Settings'.
  3. Click the 'Edit' button labelled 'Subversion configuration file'
  4. Tortoise will ask you to select a text editor, Notepad.exe will do if you don't have anything better!
  5. Scroll down to the bootom of the file and look for the [auto-props] section.
  6. Just above it is a line that is commented out '# enable-auto-props = yes'. Remove the comment.
  7. Now add this below the [auto props] heading:
    ### custom keyword substition
    *.cfc = svn:keywords=HeadURL Revision Author Date Id
    *.cfm = svn:keywords=HeadURL Revision Author Date Id
  8. Save your file and that should do it for new files you create.

If you really want to get carried away then you can also specify your own keywords to be substituted!


7 comments

  1. I'm using TortoiseSVN but I can't get this to work.

    I open Properties, click New, select svn:keywords, type them in, Apply recursively, click OK.

    It seems to alter the files (when I commit, every file is changed). However no entry appears in the Property window. Is that normal?

    I put the keywords in a file but they never change.

    Thanks,

    Comment by Ben W – January 15, 2009
  2. I managed to get it working. Do NOT type dollar signs when you specify the keywords in the Properties dialog.

    7. Enter (note that each one is on a new line)
    HeadURL
    Revision
    Author
    Date
    ID

    Comment by Ben W – January 15, 2009
  3. Thanks for spotting that Ben! Posted updated.

    Comment by John Whish – January 20, 2009
  4. thanks for the detailed steps.

    I'm looking for a way to apply keywords on already versioned files, but till now everybody is describing the steps with a note (it works with new files or imported ones).

    However, with making the keywords through the properties of the root of Local WC, it substituted keywords added to already versioned files.

    Sharing this info here because this page has the right solution.

    thanks again.

    Comment by Hussain – May 19, 2009
  5. Thanks for sharing the tip Hussain!

    Comment by John Whish – May 19, 2009
  6. Very helpful indeed thank you very much. It seems to work, but not exactly the way it should.

    I setup the svn:keywords as explained above and I use a text file to keep track of my commit logs. For this text file I enable the svn:keywords.

    I added the keywords between dollars signs as explained above.

    When I commit the textfile, the keywords are substituted correctly in my working copy in the textfile, but on the remote repository, the keywords are NOT substituted.

    Any ideas on why this happens? Am I doing something wrong?

    Regards

    Dewald

    Comment by Dewald – June 26, 2009
  7. Hi Dewald. Keyword substitution happens on the client side. If you never update your working copy, then you won't see any of the changes made by another user.

    It's worth having a read of the SVN redbook here:
    svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html

    Comment by John Whish – June 29, 2009

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments
 

Search

Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)

Categories

Recent Posts