Chris Nava
Chris Nava

Reputation: 6802

How can I check out just the trunks of multiple projects from the same repository?

We have a single SVN repository with multiple related projects. Like so...

\repo
  \Project1
    \branches
    \tags
    \trunk
  \Project2
    \branches
    \tags
    \trunk
  \Project3
    \branches
    \tags
    \trunk

I would like to check out the trunk of each project into my workspace without the branches/tags folders.

\workspace
  \Project1
    \trunk
  \Project2
    \trunk
  \Project3
    \trunk

Is there a way to do this without checking each trunk out individually?

Upvotes: 24

Views: 18227

Answers (9)

Moha Dehghan
Moha Dehghan

Reputation: 18472

I wrote this PowerShell script to checkout all the "trunk" folders in arbitrarily nested projects. Just supply $rootUrl and $rootDir values, and run the script.


$rootUrl = "https://<svn-server>/<repo-path>/"
$rootDir = "<local path to checkout into>"

# Usually, when there is a folder called "trunk" somewhere, adjacent folders
# are tags/branches, so we don't need to recurse into them.
# If this is not desired, change below variable to $false
$ignoreTrunkSiblings = $true

function FindAndCheckoutTrunk($url, $dir) {
    Write-Host -ForegroundColor DarkGray $url

    $childItems = Invoke-Expression "svn list `"$url`""
    $foundTrunk = $false
    $trunk = $childItems | Where-Object { IsTrunk $_ }
    if($trunk) {
        $foundTrunk = $true
        Checkout $url $dir $trunk
    }

    if($foundTrunk -and $ignoreTrunkSiblings) {
        return
    }

    foreach ($childItem in $childItems) {
        if(-not $childItem.EndsWith("/")) {
            # skip files
            continue
        }
        if(IsTrunk $childItem) {
            # we already checked-out this trunk folder
            continue
        }

        $subUrl = $url + $childItem
        $subDir = JoinPath $dir $childItem
        FindAndCheckoutTrunk $subUrl $subDir
    }
}

function IsTrunk($dir) {
    return $dir.TrimEnd('/').Equals("trunk", [System.StringComparison]::InvariantCultureIgnoreCase)
}

function Checkout($baseUrl, $baseDir, $childDirName) {
    $subUrl = $baseUrl + $childDirName
    $subDir = JoinPath $baseDir $childDirName

    Write-Host -ForegroundColor Cyan $subUrl
    Write-Host -ForegroundColor Green "Found trunk. Checking out..."

    $cmd = "svn checkout `"$subUrl`" `"$subDir`""
    Invoke-Expression $cmd
}

function JoinPath($path1, $path2) {
    return [System.IO.Path]::Join($path1, $path2)
}


FindAndCheckoutTrunk $rootUrl $rootDir

Upvotes: 0

pisek
pisek

Reputation: 1448

Windows batch script:

@echo off
for /f %%G in ('svn ls https://path/to/main/folder/') do (
    mkdir %%G
    cd %%G
    echo Checking out [%%G] project
    svn co https://path/to/main/folder/%%Gtrunk
)

Upvotes: 0

sunny256
sunny256

Reputation: 9606

You can use the -N option, which ignores subdirectories. You can run this the very first time you check out the sources:

svn co -N http://path/to/repo
cd repo
for f in Project1 Project2 Project3; do
  svn up -N $f
  svn up $f/trunk
done

And to update the trunks at a later time:

svn up repo/*/trunk

This works with all SVN clients. If you're using an SVN 1.5.x client, you can also have a look at "sparse directories", documented at Sparse Directories (I'm not allowed to post links yet :-C), which will allow you to run "svn update" in the repository directory.

Upvotes: 9

Marc Gravell
Marc Gravell

Reputation: 1064244

I suspect you'll still have to tell it about (checkout) each individual trunk - but you can at least also check out the workspace (to get all the projects, and so you can update, etc. globally) using sparse directories.

Upvotes: 0

st_stefanov
st_stefanov

Reputation: 1186

Right click on folder - SVN Check out. Place your URL and click "Choose Item" button. With the check boxes select the sub-folders that you want to include.

Upvotes: -1

ptrk
ptrk

Reputation: 1840

Found this to be working rather than the above:

checkoutList.bat:

for %%G in (projectA, projectB, projectC) do (
  echo %%G
  mkdir %%G
  svn co http://your.repo/path/%%G/trunk %%G
)

Upvotes: 0

Chris Nava
Chris Nava

Reputation: 6802

This did the trick nicely in bash. Note that I renamed the output folders to make Eclipse happier when importing the projects.

for f in `svn ls http://path/to/repo`; do svn checkout http://path/to/repo/${f}trunk $f; done

Upvotes: 7

Shadi Almosri
Shadi Almosri

Reputation: 11989

EDIT: check out the SVN Book for the sections below

Check out 2 different directories into two separate working copies:

$ svn checkout file:///tmp/repos/test  file:///tmp/repos/quiz
A  test/a
A  test/b
Checked out revision 2.
A  quiz/l
A  quiz/m
Checked out revision 2.
$ ls
quiz  test

Check out 2 different directories into two separate working copies, but place both into a directory called 'working copies':

$ svn checkout file:///tmp/repos/test  file:///tmp/repos/quiz working-copies
A  working-copies/test/a
A  working-copies/test/b
Checked out revision 2.
A  working-copies/quiz/l
A  working-copies/quiz/m
Checked out revision 2.
$ ls
working-copies

Upvotes: 1

Jeff Ferland
Jeff Ferland

Reputation: 18322

Short answer: no.

Long answer: See http://svnbook.red-bean.com/en/1.5/svn.advanced.sparsedirs.html and do your checkouts in a looped script.

Upvotes: 9

Related Questions