从 windows 上当前提交的visual svn 服务器上的visual svn 导出更改的文件(powershell 脚本) [英] Export the changed files from visual svn on current commit visual svn server on windows (powershell script)

查看:29
本文介绍了从 windows 上当前提交的visual svn 服务器上的visual svn 导出更改的文件(powershell 脚本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

我是 poswershell 脚本的新手.

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

它将在该提交 ($rev) 上的修订文件导出到 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?

我认为我们可以通过使用 SVN diff、SVN log 命令来实现这一点.

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

我使用的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%

推荐答案

$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. 不包括删除功能.

这篇关于从 windows 上当前提交的visual svn 服务器上的visual svn 导出更改的文件(powershell 脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆