【问题标题】:VISUALSVN Post-Commit Hooks - Get repo nameVISUALSVN 提交后挂钩 - 获取存储库名称
【发布时间】:2014-09-22 17:55:24
【问题描述】:

如何从 VISUALSVN Post-Commit Hook 中获取 repo 名称?

@echo off
set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| C:\temp\post-commit.ps1 %1 %2 'demo''
if errorlevel 1 exit %errorlevel%

我想将字符串 'demo' 替换为 repo 名称。

类似于以下 $reponame

@echo off
$reponame = SOME CODE TO GET REPO NAME
set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| C:\temp\post-commit.ps1 %1 %2 '$reponame'
if errorlevel 1 exit %errorlevel%

【问题讨论】:

    标签: svn repository visualsvn-server visualsvn


    【解决方案1】:

    由于%1 包含repo 路径,它在最后一个斜杠后面有repo 名称(例如C:/Repos/testRepo),并且您将%1 作为第一个参数传递给您的PowerShell,只需在您的PS 脚本中提取该值:

     $repoPath = $args[0]
     $index = $repoPath.LastIndexOf("/")
     $repoName =  $repoPath.Substring($index + 1, $string.Length - $index - 1)
    

    【讨论】:

      【解决方案2】:

      我在 2014 年发布了这个问题,并在 2017 年发布了一份工作副本。

      以下代码与 VisualSVN Server Post Commit Hook 一起使用

      工作代码

      # PATH TO SVN.EXE
      $svn = "C:\Program Files\VisualSVN Server\bin\svn.exe"
      $pathtowebistesWP = "c:\websites-wp\"
      
      # STORE HOOK ARGUMENTS INTO FRIENDLY NAMES
      $serverpathwithrep = $args[0]
      $revision   = $args[1]
      
      # GET DIR NAME ONLY FROM REPO-PATH STRING 
      # EXAMPLE: C:\REPOSITORIES\DEVHOOKTEST
      # RETURNS 'DEVHOOKTEST'
      $dirname = ($serverpathwithrep -split '\\')[-1]
      
      # Combine ServerPath with Dir name
      $exportpath = -join($pathtowebistesWP, $dirname);
      
      # BUILD URL TO REPOSITORY
      $urepos = $serverpathwithrep -replace "\\", "/"
      $url = "file:///$urepos/"
      
      
      # --------------------------------
      # SOME TESTING SCRIPTS
      # --------------------------------
      
      # STRING BUILDER PATH + DIRNAME
      $name = -join($pathtowebistesWP, "testscript.txt");
      # CREATE FILE ON SERVER
      New-Item $name -ItemType file
      # APPEND TEXT TO FILE
      Add-Content $name $pathtowebistesWP
      Add-Content $name $exportpath
      
      # --------------------------------
      
      
      # DO EXPORT REPOSITORY REVISION $REVISION TO THE C:\TEST FOLDER
      &"$svn" export -r $revision --force "$url" $exportpath
      

      【讨论】:

        猜你喜欢
        • 2013-03-17
        • 2013-09-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-15
        • 2011-07-31
        • 2015-09-10
        相关资源
        最近更新 更多