2014-09-22 60 views
1

如何從VISUALSVN後提交掛鉤獲取回購名稱?VISUALSVN後提交掛鉤 - 獲取回購名稱

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

我想替換字符串「演示」與回購名稱。

像下面$ 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% 

回答

2

由於%1包含回購路徑,其回購的名字在它的最後一個斜槓後面(如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服務器後提交鉤子

工作守則

# 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