26

All examples of svn branching I have seen so far look like this svn cp -m 'Making test branch' svn://svnrepo/hellosite svn://svnrepo/hellosite2

So in order to branch I need to specify full URL of remote repository every time. But:

  • Working copy is associated with one single remote repository. Even svn switch is considered to be advanced "surgical" operation.
  • Branching of remote urls in same repository as working copy is always the case (at least I have never needed to branch in repository that is completely unrelated to current one).
  • Copying between repositories is not supported (right?).
  • Information about remote repository is available: see svn info.

So why in the world should I type complete URLs every time?!! Or do I miss something? Is there some shortcut that allows referring current remote repository? Something like svn cp -m 'Making test branch' //hellosite //hellosite2

Petr Gladkikh
  • 1,906
  • 2
  • 18
  • 31

4 Answers4

44

Using SVN 1.6 or later, if you're inside a working copy at the time then you can use the caret notation as a short-cut to the repository root, e.g.

svn cp -m 'Making test branch' ^/trunk ^/branches/hellosite

Note that on Windows at least you'll need to surround the ^/trunk in double quotes to get it through the shell.

svn cp -m "Making test branch" "^/trunk" "^/branches/hellosite"
Rup
  • 33,765
  • 9
  • 83
  • 112
3

You can simply add an alias to your shell. See this this SO post for example.

Community
  • 1
  • 1
CharlesB
  • 86,532
  • 28
  • 194
  • 218
2

I've created a small bash alias file for convenient svn branching on the shell. (You can get the full file here: https://github.com/grexi/snippets/blob/master/svnaliases)

function getrepo {
    REPO=`LANG=C svn info | grep "Repository Root"`
    echo ${REPO:17}
}

function getrepobase {
   if [ "`LANG=C svn info | grep -c Relative`" -gt 0 ]; 
   then
      parent=".."
      grandparent=".."
      if [ -d ".svn" ]; then
          echo ""
      else
          while [ ! -d "$grandparent/.svn" ]; do
              parent=$grandparent
              grandparent="$parent/.."
          done
          echo $grandparent
     fi
   else
      parent=""
      grandparent="."
      while [ -d "$grandparent/.svn" ]; do
          parent=$grandparent
          grandparent="$parent/.."
      done
      echo $parent
   fi
}

function _svnbr {
    if [ $# != 2 ]; then
        echo "Usage: $0 branchname \"commit message\""
    else
        REPO=$(getrepo)
        if [ -z "$REPO" ]; then
            echo "You are not inside a svn working copy"
            return;
        fi
        svn copy $REPO/trunk $REPO/branches/$1 -m "$2"
        svn switch $REPO/branches/$1 $(getrepobase)
    fi
}
alias svnbr=_svnbr

Creating a branch now turns into

svnbr "branchname" "commit message"

inside your working directory.

Gregor
  • 4,306
  • 1
  • 22
  • 37
-4

This is one of the many weird SVN-isms that you will need to get used to.

Your assumption that you need to specify the full URL in both arguments is absolutely correct.

Floyd Price
  • 630
  • 4
  • 3