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 <$user@test.com>"
}
# log off vault
.$vaultCLCExe FORGETLOGIN