Commit hook for specific brnach

deepak8373
deepak8373
Hi My svn Reposiotry structure Trunk Branch Project1 Project2 - (want to run pre -commit hook for this branch) Project3 Tag I want to validate the commit message(Example "Def-123") before committing to svn. I want to run pre commit hook for a specific branch(Branch/Project2). I have customized my pre-commit.bat file , but it is validating for every branch before the commit. How can we customize precommit hook for specific branch. Thanks

Last updated

squeekjjy
squeekjjy
Hi, What OS are you using? The reason I ask is I think there might be a way to implant the svnlook changed command into your script. The idea is that we get it to only look at one project, if anything has been changed in that project then the pre-commit hook works, if there isn't any changes to that project then the pre-commit hook just closes down.
andyl
andyl
Parse the output of svnlook changed, test the paths, and only fire your logic for that specific branch.
andyl
andyl
[QUOTE=squeekjjy;126705]Hi, What OS are you using? The reason I ask is I think there might be a way to implant the svnlook changed command into your script. The idea is that we get it to only look at one project, if anything has been changed in that project then the pre-commit hook works, if there isn't any changes to that project then the pre-commit hook just closes down.[/QUOTE] [quote]pre-commit.bat[/quote] Implies Windows.
squeekjjy
squeekjjy
Hi Andyl, Do you think the idea I had would work using svnlook changed or maybe you have an idea on how to do this?
andyl
andyl
[QUOTE=squeekjjy;126712]Hi Andyl, Do you think the idea I had would work using svnlook changed or maybe you have an idea on how to do this?[/QUOTE] You'd definitely have to use svnlook changed from the pre-commit. I don't have specifics, as I abandoned BAT scripting a long time ago for WSH and now PowerShell.
squeekjjy
squeekjjy
[QUOTE=andyl;126716]You'd definitely have to use svnlook changed from the pre-commit. I don't have specifics, as I abandoned BAT scripting a long time ago for WSH and now PowerShell.[/QUOTE] So if we was to create one using powershell and asked the user to install the required product, do you think you would have the knowledge required to help create a working script or maybe the base bone to work with? (I've only created a couple of script's so I know you are more knowledgeable on this subject).
deepak8373
deepak8373
how can we get the branch name in the precommit hook . So that i can keep condition of this particular branch .
andyl
andyl
[QUOTE=squeekjjy;126718]So if we was to create one using powershell and asked the user to install the required product, do you think you would have the knowledge required to help create a working script or maybe the base bone to work with? (I've only created a couple of script's so I know you are more knowledgeable on this subject).[/QUOTE] I do, but I won't have time until an evening this week sometime.
squeekjjy
squeekjjy
Deepak8373, the best thing to do would ask andyl if he is able to help, but as he said, he is a little busy so you may have to wait a little bit. He is the best person to help you out with this and tbh, you are in very good hands.
andyl
andyl
Oh how I loathe Windows sometimes. Especially when having to cross the BAT/PoSH barrier in this context. This is not working, but I've spent far too much time on it thus far. pre-commit.bat:[code]@echo off C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe -file C:\_data\Repositories\Test\hooks\pre-commit.ps1 -repos_path "%1" -txn %2 1>&2 exit %ERRORLEVEL%[/code] pre-commit.ps1:[code]#requires -version 2.0 [cmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateScript({Test-Path $_})] [alias("Repository","Repo")] [string]$repos_path, [Parameter(Mandatory=$true)] [alias("transaction")] [string]$txn ) $svnProg = $changedPaths = & 'C:\Program Files\TortoiseSVN\bin\svnlook.exe' changed $repos_path -t $txn; # Branch/Project2 $runFullPreCommit = $false; foreach ($path in $changedPaths) { if ($path.Contains("Project/Branch2")) { $runFullPreCommit = $true; } } if ($runFullPreCommit) { $logContent = & 'C:\Program Files\TortoiseSVN\bin\svnlook.exe' log $repos_path -t $txn; if (-not $logContent.StartsWith("Def")) { Write-Error "Your log message did not pass validation. It must start with `"Def`""; throw 'ERROR'; } }[/code] But it's not working properly. Hopefully this is enough to get you moving forward.
srichary04
srichary04
Nee a help on the below pre-commit requirement... trunk Branch1 When user wants to commit the code changes to the Branch1 before commit the same changes to the trunk. Restrict these commits when its not committed to trunk first and then Branch. Restrict the user commit in the below (2) scenarios: Scenario1: When adding new file to Branch1 and try to commit (file not committed to the trunk) Scenario2: Changes to the existing file and try to commit to the Branch1 (Changes not committed to the trunk). TIA.
DougR
DougR
It's pretty much the same as described above: use "svnlook" to find the paths in the branch. Then make sure that those paths exist on the trunk. And perhaps diff the trunk/branch files to see that they have at least something in common...

1-13 of 13

Reply to this discussion

You cannot edit posts or make replies: You should be logged in before you can post.

Post a reply
3785 views