【问题标题】:Export the changed files from visual svn on current commit visual svn server on windows (powershell script)在 Windows 上的当前提交视觉 svn 服务器上从视觉 svn 导出更改的文件(powershell 脚本)
【发布时间】:2016-06-19 04:15:21
【问题描述】:

需要在windows上当前提交的visual svn服务器上从visual svn导出更改的文件。

我尝试在提交后使用 windows power shell 脚本和 bat 文件来实现这一点。

我是 poswershell 脚本的新手。

我得到了导出当前版本的代码。如下。

# 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

它将在该提交 ($rev) 上将修订版文件导出到 F:\test_live

但我只需要导出更改的文件。 他们有什么办法吗?

我认为我们可以通过使用 SVN diff、SVN log 命令来实现 thsi。

我使用的bat文件是

@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%

【问题讨论】:

  • 为什么只想导出更改的文件?
  • @Dangph 非常感谢您检查我的问题,由于文件变得更多,提交过程变得太慢,因为它需要导出所有文件。所以我认为最好只导出更改的文件。
  • @Dangph 我看到了 Bash 脚本,但我不知道如何将其转换为 powershell 脚本。 :(electrictoolbox.com/subversion-export-changed-files-cli-v2
  • 为什么你不能只在 F:\test_live 上做一个结帐,然后在每次提交后在那里做一个svn update
  • 是的,谢谢,我以前试过这个。但它将成为工作副本:(。我正在尝试制作它而不将其作为工作副本。

标签: windows svn powershell visualsvn-server


【解决方案1】:
$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

    }
}

已知错误:

  1. 带有“空格”的文件夹/文件名不能正常工作
  2. 不包括删除功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多