How to export svn with automatic creation of relative directory / path?

I usually do it manually:

  • mkdir -p folder1/foder2/folder3

  • cd folder1/foder2/folder3

  • svn export svn://127.0.0.1/svn/app1/branches/branch1/folder1/foder2/folder3/file1.txt

Is there a way or direct command to export svn that I don't need to do steps 1 and 2? I hope it will be easier there, that svn will automatically create the directory structure from SVN to my local machine.

Thank!

+3


source to share


4 answers


If there is a known hardcoded path in the repository - yes, just write the destination path in the export (manually)

svn export svn://127.0.0.1/svn/app1/branches/branch1/folder1/foder2/folder3/file1.txt folder1/foder2/folder3/file1.txt



In the case of a dynamically changing relative path, no, you have no internal presets. But if you export the content of the revision from the repository, you can implement it with subcommands svnlook

and your own logic in the code

0


source


Ok, now I have come up with a bash script that creates a relative path. I don't have in-depth knowledge of bash scripting, so this is ugly. Please forgive me. But hopefully it makes you think.

svn_export.sh

#!/bin/sh
for var in "$@"
do
    svnArg1=$var;
    svnArg2=`echo "$svnArg1" | sed -e 's/file:\/\/\/usr\/share\/svn\///'`;

    tempDir=`dirname $svnArg2`;
    tempFile=`basename $svnArg2`;
    if [ -n "$tempFile" ]; then

        if [ ! -d "$tempDir" ]; then
            echo "mkdir -p $tempDir";
            echo `mkdir -p $tempDir`;
        fi    

        echo "svn export $svnArg1 $svnArg2";
        echo `svn export $svnArg1 $svnArg2`;

    fi

done

exit 0;

      

Application:

sudo svn diff -r 1:HEAD --summarize file:///usr/share/svn/TestRepository/ | awk '{print $2}' | xargs ./svn_export.sh

Output



A TestRepository/trunk/test2.txt Export complete.
A TestRepository/trunk/test3.txt Export complete.
A TestRepository/trunk/test.txt Export complete.

      

Basically, you just need to change this line file:\/\/\/usr\/share\/svn\/

in the argument sed

to all of your svn urls.

Example: svn:\/\/127.0.0.1\/svn\/project1\/branches\/

So now the usage will look like this:

svn diff -r 1540:HEAD --summarize svn://172.0.0.1/svn/project1/branches/branch1 | awk '{print $2}' | xargs ./svn_export.sh

      

Hope this helps!

0


source


It seems that the svn export/checkout

equivalent -p

in svn export/checkout

as in mkdir

is the best way to make the function in.bashrc

function svnExport() {
    mkdir -p "$(dirname "$1")" && svn export "$0$1" "$1"
}

      

So your specific example would be

svnExport 'svn://127.0.0.1/svn/app1/branches/branch1/' 'folder1/foder2/folder3/file1.txt'

      


EDIT: Turns out it --force

will handle subdirectories, but has side effects such as automatic overwriting. So if it doesn't bother you, you can simply do

svn export --force 'svn://127.0.0.1/svn/app1/branches/branch1/folder1/foder2/folder3/file1.txt' 'folder1/foder2/folder3/file1.txt'

      

or

function svnExport() {
    svn export --force "$0$1" "$1"
}

      

0


source


I tried to do it with SVN UI and it worked fine.

Let's say I have a folder called 'abc'. I want to export to the "build" folder (which doesn't exist) a file.

Image showing source url and destination directory

This will export the file successfully after creating the build folder. As far as command line parameters go, I've tried every possible way. It doesn't create a new folder. The folder must already exist.

0


source







All Articles