How To Check If The Local SVN Revision Is Up-To-Date

Posted by Artem Russakovskii on July 23rd, 2008 in Linux, Programming

I've encountered a problem recently where I had to figure out if some checked out code is up-to-date with the svn repository, without actually running svn update. Unfortunately, svn update doesn't have a dry-run option, so I had to find another solution.

I came up with 2, depending on how detailed the information needs to be, which I'm about to share in this post.

1. If you want exact file and directory names, you can run:

svn status -u

If any files need updating, you will see a * before the file name.

svn status wc
M     wc/bar.c
A  +   wc/qax.c

svn status -u wc
M            965    wc/bar.c
       *     965    wc/foo.c
A  +         965    wc/qax.c
Status against revision:   981

Or more verbose

svn status --show-updates --verbose wc
M            965       938 kfogel       wc/bar.c
       *     965       922 sussman      wc/foo.c
A  +         965       687 joe          wc/qax.c
             965       687 joe          wc/zig.c
Status against revision:   981

Parsing the output in Perl, for instance, should be trivial. A connection to the repository is established for this check, so be sure to catch in your code the times when such connection is not available.

2. If you only care about whether a specific directory needs to be updated or not, here's a quicker method:

svn info vs svn info -rHEAD

cd somedir;
svn info -r HEAD | grep -i "Last Changed Rev"
Last Changed Rev: 8544
svn info | grep -i "Last Changed Rev"
Last Changed Rev: 8531

If these numbers are not the same, an update is needed.

What can I be missing? Are there any other creative ways, or is svn update going to support dry-run? Feel free to leave a comment if you know something I don't.

● ● ●

Artem Russakovskii is a San Francisco programmer, blogger, and future millionaire (that last part is in the works). Follow Artem on Twitter (@ArtemR) or subscribe to the RSS feed.

In the meantime, if you found this article useful, feel free to buy me a cup of coffee below.

  • math0ne

    This is some very helpful info m8!

  • Michael Krebs

    Just right. Thanks.

    Also, if you want to find out what the pending changes look like before you svn up, you can use:

    svn diff -r HEAD wc/foo.c

    Don't forget this will include both unchecked-in local changes (if any) and unchecked-out changes in the repository.

  • Michael Krebs

    UPDATE: if you only want to see the changes that would be merged into the working copy if you update from the repository, you can use:

    svn diff -r HEAD:BASE wc/foo.c