Skip to content

Instantly share code, notes, and snippets.

@rmpel
Created December 10, 2015 13:47
Show Gist options
  • Save rmpel/77662cd3158f48f30838 to your computer and use it in GitHub Desktop.
Save rmpel/77662cd3158f48f30838 to your computer and use it in GitHub Desktop.
script to easily tag a Subversion project
#!/bin/bash
SVN=/usr/local/bin/svn
[ ! -f "$SVN" ] && SVN=/usr/bin/svn
trunk_or_branch_status () {
echo "Status on SVN ($1)"
TRUNKREV=` svn info "$1" | grep "Last Changed Rev" | egrep -o [0-9]+ `
TAGSREV=` svn info "$2"/tags | grep "Last Changed Rev" | egrep -o [0-9]+ `
[ $TRUNKREV -gt $TAGSREV ] && echo There are changes not yet tagged \! \( HEAD: $TRUNKREV, Tags: $TAGSREV \) && svn log -r $TAGSREV:$TRUNKREV
[ $TRUNKREV -le $TAGSREV ] && echo No action needed\!
}
[ ! -d ".svn" ] && echo Use only inside the main project directory under SVN control && exit
S=` $SVN info | grep URL: | cut -d " " -f 2 `
BSE=` echo $S | sed 's/\/trunk/ /' | sed 's/\/branches/ /' | sed 's/\/tags/ /' | cut -d " " -f 1 `
B=$BSE/tags
T=$BSE/tags/$1
[ "$1" == "" ] && echo Usage: $0 TAG Commit comment && echo latest tags: && $SVN ls "$B" | tail -n 5
[ "$1" == "" ] && trunk_or_branch_status "$S" "$BSE"
[ "$1" == "" ] && exit
IFS=$'\n';
tags=` $SVN ls $B `
for i in $tags; do
lasttag=$i
done
lasttag=` echo $lasttag | sed 's_/__g' `
for i in $tags; do
[ "$1/" == "$i" ] && echo tag $1 already exists, please create a tag higher than $lasttag && exit;
done
M=$@
echo Executing: $SVN cp "$S" "$T" -m "Release $M"
$SVN cp "$S" "$T" -m "Release $M"
@rmpel
Copy link
Author

rmpel commented Dec 10, 2015

This script can be used to easily create a tag from within the working-copy (checkout) of the trunk of a project.
Syntax:
svntag.sh 0.0.3
to tag version 0.0.3

The script was developed with WordPress in mind; for themes, style.css is checked for a matching version number, for plugins, all php files in the root are checked (no file-naming-convention exists for this)

Checks are done to prevent errors;

  • all files need to be committed, no unversioned files, changed files etc are allowed
  • version number needs to match
  • tag may not already exist

important to know that there is NO check for old version numbers; if you have a tag 0.0.3 and 1.0.0, you CAN tag 0.0.4 through 0.9.9, but this probably is not very good practice :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment