2014-09-22 3 views
1

VISUALSVN 후 커밋 후크에서 repo 이름을 얻으려면 어떻게해야합니까?VISUALSVN 사후 커밋 후크 - 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% 

나는 문자열 '데모'를 REPO 이름으로을 대체하고 싶습니다. 다음 $ 같은

뭔가 %1

@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

마지막 슬래시 뒤에에서 REPO 이름이 REPO 경로 (예 : C:/Repos/testRepo)을 포함 reponame, 당신은 첫째로 PowerShell을에 %1을 전달하는 인수로 PS 스크립트에서 그 값을 추출하면됩니다 :

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

나는이 질문을 2014 년과 2017 년에 올렸습니다. 저는 작업 복사본이 있습니다.

아래의 코드는 후크를

작업 코드

# 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 
커밋 VisualSVN 서버 포스트와 함께 사용