~vijaykumar

[ Home | Feed | Twitter | Vector Art | Ascii Art | Tutorials ]

Finding the Lastest SVN Tag

Tue, 14 Oct 2014

The following script finds the latest tag on an SVN project. The basic idea is to use svn info to find the last revision of the tags folder, and identify the tag with that revision. If the tags folder is not present, or if the tags folder is present but empty, the script prints N/O/N/E.

#!/bin/bash

#
# Usage: svn-latest-tag <SVN-PROJ-URL>
#
# Prints the latest tag or N/O/N/E if none available.
#

if [ "x$1" == "x" ]; then
    echo "Usage: svn-latest-tag <SVN-PROJ-URL>"
    exit 1
fi

#
# Tag name to be printed if none found, less likely to be a real tag
# name. (directories cannot contain the forward slash, right?)
#

latest_tag="N/O/N/E"
tags=$(svn ls $1/tags)
if [ $? -ne 0 ]; then
    echo $latest_tag
    exit 1
fi
last_rev=$(svn info $1 | grep "Last Changed Rev")
if [ $? -ne 0 ]; then
    echo $latest_tag
    exit 1
fi
# echo $last_rev
for tag in $tags; do
    # echo "Checking tag" $tag
    if svn info $1/tags/$tag | grep "$last_rev"; then
        latest_tag=tag
        break
    fi
done
echo $latest_tag

Permalink | Add Comment | Share: Twitter, Facebook, Buzz, ... | Tags: doc, foss, svn

Powered by Python | Made with PyBlosxom | Valid XHTML 1.1 | Best Viewed With Any Browser | Icon Credits | CC-BY-SA