35

Is there a way to perform a SVN checkout (or export), which would fetch only the directory structure; that is to say, no files?

Makoto
  • 104,088
  • 27
  • 192
  • 230
petr k.
  • 8,040
  • 7
  • 41
  • 52
  • Just curious - why would you want to do this? – Tim Feb 11 '09 at 15:18
  • 2
    @Tim: Seems like a nice way to set up the directory structure for a new project, based on that of an existing project. – onnodb Feb 11 '09 at 15:41
  • @onnodb: Yes, but that's why you should have templates ready for your new projects, just export a template and you're ready. – mbillard Feb 11 '09 at 15:47
  • No no, I want to do some postprocessing on the directory structure in my NAnt/MSBuild tasks. – petr k. Feb 11 '09 at 15:57
  • 2
    I'll add another reason - we have a large SVN structure used for many things (not source code). I want to be able to just sync the directories I care about, but want the whole structure locally. It's not a normal path case, but seems like it would be useful. – Cory Foy Jul 08 '10 at 14:20
  • You should check this post(but if the directory depth is deep, maybe can't fulfill your demand), http://svnbook.red-bean.com/en/1.7/svn.advanced.sparsedirs.html – dreamtale Dec 20 '13 at 02:57
  • Check this thread out: http://stackoverflow.com/questions/4032059/how-to-checkout-few-files-and-folders-alone-without-checking-out-entire-source – smwikipedia Mar 13 '16 at 05:47

12 Answers12

13
svn ls -R {svnrepo} | grep "/$" | xargs -n 1 mkdir -p

Export, not a checkout.

[Updated]

With checkout:

env REPO={repo} sh -c 'svn ls -R $REPO | grep "/\$" | xargs -n 1 svn co --depth=empty $REPO'

This will be pretty slow for anything too large.

Gregor
  • 4,306
  • 1
  • 22
  • 37
Dave Stenglein
  • 1,420
  • 1
  • 12
  • 14
  • Is it possible to do this with an actual SVN checkout? I want to have a copy of all the directories that is under version control (ie: has a .svn subfolder in each directory, just as if I were to perform "svn co --non-recursive" on each folder). – Cloud Apr 05 '12 at 18:22
  • Use this instead if you happen to have spaces in folder names: svn ls -R {svnrepo} | grep "/$" | xargs -I {} mkdir -p "{}" – architectonic Sep 21 '15 at 11:19
  • worked nicely for me to get me started with an empty working copy: https://resbook.wordpress.com/2011/01/06/check-out-directory-in-svn-without-checking-out-the-content-of-directory/ – i_a Jan 30 '16 at 02:13
  • 2
    A variation on @architectonic's comment, to also handle filenames with quotation marks, etc.: `svn ls -R {svnrepo} | grep "/$" | tr '\n' '\0' | xargs -0 -n 1 mkdir -p` – Robert Fleming Apr 04 '17 at 01:19
9

You can specify --non-recursive to the checkout command, might help you to get what you want.

  • 3
    I don't see how this would help. `--non-recursive`, does what it says: it doesn't recurse down the tree. So this would only give you top-level objects, which is not what the OP wants, unless they have a flat directory structure (a shrub instead of a tree). – SQB Jun 11 '14 at 07:01
5

There is a python script in the contrib tools of subversion, which creates the directory structure with empty files. With a little bit of python knowledge, it should not be to hard to skip creating the files at all.

martin clayton
  • 76,436
  • 32
  • 213
  • 198
jor
  • 711
  • 3
  • 7
4

SVN can't do that per se, but if you just want to export directory structure, try svn ls -R --xml to get XML listing of the directory structure and then recreate it by hand.

Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
4

A use for checking out just the directory structure is a partial workaround for not being able to exclude one or more directories from being checked out. It is assumed that the cost of just checking out the directory tree is negligible in comparison to checking out the full source. With a versioned directory structure checked out I could then use Subversion's update and sparse directories to selectively pick what directory trees should have files.

Andrew Gilmartin
  • 1,776
  • 12
  • 12
3

This works perfectly

svn ls | xargs svn up -N

And then if you want to get few of those directories fully checked out, go inside them and use

svn ls | xargs svn up
Darshan
  • 116
  • 1
  • 1
  • 8
2

Just wanted to add, if you need to do this server-side (i.e. not checking out the repository first), the equivalent to svn ls is svnlook tree --full-paths. I had to create a copy of a 50GB repo's folder structure and used the hints I found here to do it without having to create a working copy of the whole thing.

My code was:

svnlook tree /path/to/repo --full-paths | grep "/$" | grep -v "^/$" | xargs -I {} mkdir -p "{}"

The grep -v "^/$" because the output contained a single / (i.e. file system root folder) and I didn't want to mess around with that.

namezero
  • 2,203
  • 3
  • 24
  • 37
1

My DotNet (LINQ) way to do this:

First, run the svn list command. And push the output to an .xml file.

"svn.exe" list "https://myserver.com:8443/svn/DotNet/src/v40Base/v40/" --recursive --username %USERNAME% --xml >>myfile.xml

And then run some LINQ code against the .xml file.

    private static void FindSVNDirectories()
    {

        string fileName = @"C:\temp\myfile.xml";

        XDocument xDoc = XDocument.Load(fileName);

        //XNamespace ns = XNamespace.Get("http://schemas.microsoft.com/developer/msbuild/2003");
        string ns = string.Empty;

        //List of directories
        var list1 = from list in xDoc.Descendants(ns + "list")
                    from item in list.Elements(ns + "entry")
                    where item.Attribute("kind").Value=="dir"
                    select new
                       {
                           mykind = item.Attribute("kind").Value,
                           myname = (item.Element(ns + "name").Value)
                       };

        StringBuilder sb = new StringBuilder();
        foreach (var v in list1)
        {
            sb.Append(v.ToString() + System.Environment.NewLine );
        }

        Console.WriteLine(sb.ToString());


    }
granadaCoder
  • 26,328
  • 10
  • 113
  • 146
1

on windows and with TortoiseSVN you can do Checkout -> checkout depth: only this item. this way you can get single folders/files. you could rebuild your structure this way (using the repobrowser). a bit cumbersome, but doable if your directory structure is not too complicated. i preferred this over checking out thousands of small files (several gigabytes) over slow network ...

didito
  • 748
  • 7
  • 17
  • 1
    Or in the same screen, you can leave the `Checkout depth` as `Fully recursive` and in the button right bellow the combobox, named `Choose Items`, you can uncheck the files you don't want to grab. – Canella Nov 10 '11 at 12:24
1

You may use this script which will svn list the repos and create the structure in a directory.

usage: perl checkout-structure.pl repos destdir

repos must not be the root of your repos, it can also precise a directory.

Fails to create dirs containing accentuated caracters (àéîùç...), but works fine with spaces. For these who have time for that, I think it's an encoding problem.

checkout-structure.pl:

#!perl

my @dirs;
my $repos = shift;
my $dest = shift;

@dirs = grep { /\/$/ && /^[^\.]/ } `svn list -R $repos`;

foreach(@dirs) {
    s/\/$//;
    chomp;
    mkdir("$dest/$_") or warn $!." trying to create $dest/$_";
}
René Höhle
  • 26,716
  • 22
  • 73
  • 82
E. Fetille
  • 11
  • 1
0

I can't see that there is a way to do it from a brief look at svn help co. Something I've done before for updating a repository from a new version of a downloaded library (i.e. a vendor branch) is to delete everything which isn't an .svn folder:

#!/bin/sh
find ./ -type f | grep -v .svn | xargs rm -f

It's not particularly efficient if you were trying to avoid having to check those files out in the first place, but it should have the same result.

Kothar
  • 6,579
  • 3
  • 33
  • 42
-1

There's no way to do this, and in fact it's a slightly odd thing to want to do, so now I'm curious!

This may not be relevant, but you can prevent the files being comitted in the first place by adding an svn:ignore property on the relevant directories. This is particularly useful to prevent generated artifacts such as documentation or cache files being comitted.

12345
  • 529
  • 5
  • 7
  • I want to replicate the repository directory structure on my local drive and then do further processing using other tools (NAnt/MSBuild). svn:ignore is not relevant. – petr k. Feb 11 '09 at 15:21