SVN: Checkout/export only the directory structure

后端 未结 12 1110
花落未央
花落未央 2020-12-08 19:14

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

相关标签:
12条回答
  • 2020-12-08 19:42

    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/$_";
    }
    
    0 讨论(0)
  • 2020-12-08 19:42

    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.

    0 讨论(0)
  • 2020-12-08 19:48

    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.

    0 讨论(0)
  • 2020-12-08 19:49

    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
    
    0 讨论(0)
  • 2020-12-08 19:51

    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());
    
    
        }
    
    0 讨论(0)
  • 2020-12-08 19:56

    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.

    0 讨论(0)
提交回复
热议问题