Is there a way to import/export SourceGear Vault to Git

4.3k views Asked by At

I have a source control system using SourceGear Vault.

I'm playing with Git and wanted to see if I could get my SourceGear repo into Git.

I cannot see any way to do this.

Can anyone recommend a way of doing this?

I have found a Folder Export/Import tool which creates a VFE file extension.

2

There are 2 answers

0
Jon On BEST ANSWER

Looks there is no tool to do this unless I write it myself! http://support.sourcegear.com/viewtopic.php?f=5&t=18994

UPDATE: There does seem to be a possible solution with Vault2Git

0
WiktorM On

It's an old topic but I faced the same challenge in 2023. The mentioned Vault2Git wasn't working fine in my case. I also had issues with another solution on GitHub using Ruby. So I decided to create my own solution. Sharing it here if someone else needs it.

I just used PowerShell and Vault CLC (Command Line Client). It can be downloaded from SourceGear website for free.

$vaultCLCExe = [PATH TO VAULT CLC]
$localRepository = [PATH TO LOCAL GIT REPO]
$vaultRepositoryName = [NAME OF VAULT REPO]

# authenticate in Vault
.$vaultCLCExe -user [VAULT USER] -password [VAULT PASSWORD] -host [VAULT SERVER] -ssl REMEMBERLOGIN -repository $vaultRepositoryName

# set working folder to local git repository
.$vaultCLCExe SETWORKINGFOLDER $ $localRepository
Set-Location $localRepository

# get full history for repository
[xml]$fullVaultRepoHistoryXML = .$vaultCLCExe HISTORY $

# convert it to custom object so it's easier to use it
$history = $fullVaultRepoHistoryXML.vault.history.ChildNodes | % {
    [PSCustomObject]@{
        txid         = [int]$_.txid
        date         = $_.date
        name         = $_.name
        type         = $_.type
        typeName     = $_.typeName
        version      = [int]$_.version
        objverid     = $_.objverid
        user         = $_.user
        actionString = $_.actionString
    }
}

# get root folders
[xml]$folders = .$vaultCLCExe LISTFOLDER $
$allRootFolders = $folders.vault.folder.ChildNodes.name


# get history of root folders
$allRootFoldersHistory = @{}
foreach ($folder in $allRootFolders){
    [xml]$tempF = .$vaultCLCExe VERSIONHISTORY $folder -rowlimit 0
    $allRootFoldersHistory.Add($folder, $tempF)
}

# get check-ins
$txIDs = $history.txid | select -Unique | sort
[xml]$vaultCommits = .$vaultCLCExe VERSIONHISTORY $ 

# process each check-ins
foreach ($id in $txIDs){
    $events = $history | ? {$_.txid -eq $id} 
    $allRootFoldersAffectedInEvents = $events.name | %{($_ -split("/"))[0..1] -join('/')}
    foreach ($folder in $allRootFolders){
        if ($allRootFoldersAffectedInEvents -contains "$folder"){
            $versionHistoryFolder = $allRootFoldersHistory["$folder"]
            if ($versionHistoryFolder.vault.history.ChildNodes.txid -contains $id){
                $folderVersionToGet = $versionHistoryFolder.vault.history.ChildNodes | ? {$_.txid -eq $id}
                $localFolderPath = $folder.Replace("$",$localRepository).Replace("/","\")
                if (Test-Path $localFolderPath) {
                    Get-ChildItem $localFolderPath | Remove-Item -Recurse -Force
                }
                .$vaultCLCExe GETVERSION $folderVersionToGet.version $folder -backup no -merge overwrite -nocloaks -setfiletime checkin -performdeletions removeworkingcopy
            }
        }
    }

    $commit  = $vaultCommits.vault.history.ChildNodes | ? {$_.txid -eq $id}
    $date    = $commit.date
    $user    = $commit.user
    $comment = $commit.comment
    git add -A
    git commit -m "$comment" --date=$date --author="$user <[email protected]>"
}

# log off vault
.$vaultCLCExe FORGETLOGIN