Export the changed files from visual svn on current commit visual svn server on windows (powershell script)

StackOverflow https://stackoverflow.com/questions/23670606

Pergunta

Need to export the changed files from visual svn on current commit visual svn server on windows.

I tried using windows power shell script and bat file on post-commit to achieve this.

I'm new to poswershell scripting.

I got the code to export current revision. It is as follows.

# Store hook arguments into variables with mnemonic names
$repos = $args[0]
$rev   = $args[1]

# Build path to svn.exe
$svn = "$env:VISUALSVN_SERVER\bin\svn.exe"

# Build url to repository
$urepos = $repos -replace "\\", "/"
$urepos
$url = "file:///$urepos/"

# Export repository revision $rev to the C:\test folder
&"$svn" export -r $rev --force "$url" F:\test_live

It will export the files on the revison on that commit ($rev) to F:\test_live

But I need to export only changed files. Is their any way to do?

I think we can achieve thsi by using SVN diff, SVN log commands.

The bat file I'm using is

@echo off

set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| %1\hooks\post-commit.ps1 %1 %2  
if errorlevel 1 exit %errorlevel%
Foi útil?

Solução

$repos = "C:\Repositories\siterepo"
$rev = $args[1]
$prev_rev = $rev
$prev_rev -= 1

# Build path to svn.exe
$svn = "$env:VISUALSVN_SERVER\bin\svn.exe"

# Build url to repository
$urepos = $repos -replace "\\", "/"
$urepos
$url = "file:///$urepos/"
$url

$diff_var = &"$svn" diff --summarize -r $rev:$prev_rev $url
$dif_var
$check = "System.String".CompareTo($diff_var.GetType().FullName)
if ($check -eq 0)
{
    #"single file"
    $source_file = $diff_var.Substring(8)
    $source_file
    $destination_file = "C:\mywebroot\"+$diff_var.Remove(0,41)
    $destination_file
    #check directory
    $dir_path = Split-Path $destination_file
    $dir_path
    if ((Test-Path $dir_path) -eq 0)
    {
        #"folder_not exist"
        New-Item -Path $dir_path -Force -ItemType Directory
    }
    else
    {
        #"folder exist"
    }
    &"$svn" export --force $source_file $destination_file
}
else
{
    #"multiple files"
    $num_files = $diff_var.Length
    #"loop"
    for ($i=0; $i -lt $num_files; $i++)
    {

        $source_file = $diff_var[$i].Substring(8)
        $source_file
        $destination_file = "C:\mywebroot\"+$diff_var[$i].Remove(0,41)
        $destination_file
        #check directory
        $dir_path = Split-Path $destination_file
        $dir_path
        if ((Test-Path $dir_path) -eq 0)
        {
            #"folder_not exist"
            New-Item -Path $dir_path -Force -ItemType Directory
        }
        else
        {
            #"folder exist"
        }
        &"$svn" export --force $source_file $destination_file

    }
}

Known BUGS :

  1. folders/file's name with "space" cannot work well
  2. Delete functionality is not included.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top