Skip to content

Instantly share code, notes, and snippets.

@werm098
Last active July 28, 2017 15:17
Show Gist options
  • Save werm098/babd25c69c2f7b963fcc0b7afb975f2e to your computer and use it in GitHub Desktop.
Save werm098/babd25c69c2f7b963fcc0b7afb975f2e to your computer and use it in GitHub Desktop.
Simple bash functions for working with SVN
function svnbranchname() {
svn info | grep "^Relative URL" | grep -oE "[^/]+$"
}
function svnmkbranch() {
if [ -z "$1" ]; then
echo "Error: Missing new branch name arg"
return
fi
local url=$(svn info | grep "^URL"); url=${url:5}
if [[ $url == *"/branches/"* ]]; then
local urlStringLength=${#url}
local branchName=$(svnbranchname)
local repoUrl=${url:0:urlStringLength-(10+${#branchName})}
local trunkUrl=$repoUrl"/trunk"
local newBranchUrl=$repoUrl"/branches/"$1
svn cp -m "created new branch" $trunkUrl $newBranchUrl
svn switch $newBranchUrl
else
echo "Error: You need to be in the branches directory for this to work"
fi
}
function svnmergebranch() {
if [ -z "$1" ]; then
echo "Error: Missing branch name to merge"
return
fi
local url=$(svn info | grep "^URL"); url=${url:5}
if [[ $url == *"/branches/"* ]]; then
local urlStringLength=${#url}
local branchName=$(svnbranchname)
local repoUrl=${url:0:urlStringLength-(10+${#branchName})}
local mergeBranchUrl=$repoUrl"/branches/"$1
svn merge $mergeBranchUrl
else
echo "Error: You need to be in the branches directory for this to work"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment