Skip to content

Instantly share code, notes, and snippets.

@joshcarr
Created October 26, 2010 23:26
Show Gist options
  • Select an option

  • Save joshcarr/648079 to your computer and use it in GitHub Desktop.

Select an option

Save joshcarr/648079 to your computer and use it in GitHub Desktop.

Revisions

  1. joshcarr revised this gist Oct 28, 2010. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,9 @@
    #!/bin/bash

    # USAGE:
    # ./svn-export revision-from revision-to repository target-directory
    # ./svn-export 20 25 svn://localhost/myrepository .

    if [ ! $1 ] || [ ! $2 ] || [ ! $3 ] || [ ! $4 ]; then
    echo "Please enter a revision from, revision to, SVN repository, and target directory"
    exit
  2. @invalid-email-address Anonymous created this gist Oct 26, 2010.
    39 changes: 39 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/bin/bash

    if [ ! $1 ] || [ ! $2 ] || [ ! $3 ] || [ ! $4 ]; then
    echo "Please enter a revision from, revision to, SVN repository, and target directory"
    exit
    fi

    # set up nice names for the incoming parameters to make the script more readable
    revision_from=$1
    revision_to=$2
    repository=$3
    target_directory=$4

    # the grep is needed so we only get added/modified files and not the deleted ones or anything else
    # if it's a modified directory it's " M" so won't show with this command (good)
    # if it's an added directory it's still "A" so will show with this command (not so good)

    for line in `svn diff --summarize -r$revision_from:$revision_to $repository | grep "^[AM]"`
    do
    # each line in the above command in the for loop is split into two:
    # 1) the status line (containing A, M, AM, D etc)
    # 2) the full repository and filename string
    # so only export the file when it's not the status line
    if [ $line != "A" ] && [ $line != "AM" ] && [ $line != "M" ]; then
    # use sed to remove the repository from the full repo and filename
    filename=`echo "$line" |sed "s|$repository||g"`
    # don't export if it's a directory we've already created
    if [ ! -d $target_directory$filename ]; then
    directory=`dirname $filename`
    mkdir -p $target_directory$directory
    svn export -r $revision_to $line $target_directory$filename
    fi
    fi
    done

    # to summarize any deleted files or directories at the end of the script uncomment the following line
    #svn diff --summarize -r$revision_from:$revision_to $repository | grep "^[D]"

    # thx to: http://www.electrictoolbox.com/subversion-export-changed-files-cli/