【问题标题】:Powershell Script to navigate files in SVN directory用于在 SVN 目录中导航文件的 Powershell 脚本
【发布时间】:2016-04-01 18:57:03
【问题描述】:

我需要使用 PowerShell 脚本从 SVN 位置而不是 windows 位置导航文件,如果我用 SVN 路径替换 windows 路径它不起作用,我有以下 windows 位置的工作代码:

function CheckPath($path)
{    
Test-Path $path -PathType Container
}

function Navigate()
{
$directory = "C:\Test" 
#Instead of above windows path I want to give SVN path as below: 
#https://svn.test.local/svn/Files/
$qscomponent="SomeValue"

if (CheckPath -path $directory)
{
Write-Host "Executing scripts from $directory"
Get-ChildItem $directory -Filter LTR*.sql | Foreach-Object -Process {              RunScript -comp $component -file $_.FullName   }
}
else
{
Write-Host "Invalid component: the path does not exist!"
}   
}

【问题讨论】:

  • AFAIK,文件系统提供程序不支持通过 HTTP 浏览目录。
  • 好的,那我如何从 SVN 中挑选和执行文件。我不想在 Windows 位置/目录上查看它们。
  • 先下载,然后本地执行

标签: powershell powershell-2.0 powershell-3.0


【解决方案1】:

您无法执行远程 SVN 服务器上的任何操作。这样做的任何方式都必须包括至少在本地下载该文件。

也就是说,为了使这完全透明,您可以创建依赖于svn ls 命令的脚本。

一个例子是改变prompt函数,这样当你cd进入某个文件夹时,它会得到svn文件列表(最好使用set-location的代理)但提示更容易。假设您有.svn 文件夹但没有文件(对于这组depth to empty when doing checkout

function prompt() {
    $lastCmd = h | select -Last 1 -expand CommandLine
    if ($lastCmd -match '^cd ') {
        $x = svn info
        if ($x -ne $null) {
            svn ls | % {Write-Host $_}
        }
    }

    "PS $pwd>"
}

当您进入文件夹时,此提示功能将列出您在 svn 远程存储库中的所有文件。您可以创建一个简单的 powershell 函数来下载所需的文件并执行它(svn 可以签出单个文件)。

如果您代理 cdls,它会感觉更 Powershelly,因为您实际上可以返回您可以通过管道传输到例如执行函数的项目数组,例如:

ls *.exe | execute   

其中lsproxied 并在svn 存储库本地路径内执行,execute 对管道文件使用svn checkout,可能是TEMP 并执行它们。

【讨论】:

    猜你喜欢
    • 2010-12-15
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 2015-08-03
    • 2019-07-21
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    相关资源
    最近更新 更多