How do you determine the latest SVN revision number rooted in a directory?

前端 未结 10 1696
北恋
北恋 2020-12-02 15:45

I would like to start tagging my deployed binaries with the latest SVN revision number.

However, because SVN is file-based and not directory/project-based, I need to

10条回答
  •  无人及你
    2020-12-02 16:20

    svnversion seems to be the cleanest way to do this:

    svnversion -c /path/to/your-projects-local-working-copy/. | sed -e 's/[MS]//g' -e 's/^[[:digit:]]*://'
    

    The above command will clean out any M and S letters (indicating local modifications or switchedness) from the output, as well as the smaller revision number in case svnversion returns a range instead of just one revision number (see the docs for more info). If you don't want to filter the output, take out the pipe and the sed part of that command.

    If you want to use svn info, you need to use the "recursive" (-R) argument to get the info from all of the subdirectories as well. Since the output then becomes a long list, you'll need to do some filtering to get the last changed revision number from all of those that is the highest:

    svn info -R /path/to/your-projects-local-working-copy/. | awk '/^Last Changed Rev:/ {print $NF}' | sort -n | tail -n 1
    

    What that command does is that it takes all of the lines that include the string "Last Changed Rev", then removes everything from each of those lines except the last field (i.e. the revision number), then sorts these lines numerically and removes everything but the last line, resulting in just the highest revision number. If you're running Windows, I'm sure you can do this quite easily in PowerShell as well, for example.

    Just to be clear: the above approaches get you the recursive last changed revision number of just the path in the repo that your local working copy represents, for that local working copy, without hitting the server. So if someone has updated something in this path onto the repository server after your last svn update, it won't be reflected in this output.

    If what you want is the last changed revision of this path on the server, you can do:

    svn info /path/to/your-projects-local-working-copy/.@HEAD | awk '/^Last Changed Rev:/ {print $NF}'
    

提交回复
热议问题