<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Hook on Ash Tewari</title><link>https://www.tewari.info/tag/hook/</link><description>Recent content in Hook on Ash Tewari</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Thu, 01 Apr 2010 04:32:10 +0000</lastBuildDate><atom:link href="https://www.tewari.info/tag/hook/feed.xml" rel="self" type="application/rss+xml"/><item><title>Code Validation in TortoiseSVN pre_commit_hook</title><link>https://www.tewari.info/2010/03/31/code-validation-in-tortoisesvn-pre_commit_hook/</link><pubDate>Thu, 01 Apr 2010 04:32:10 +0000</pubDate><guid>https://www.tewari.info/2010/03/31/code-validation-in-tortoisesvn-pre_commit_hook/</guid><description>&lt;p&gt;If you want to abort a commit if your code fails certain rule and you don&amp;rsquo;t have access to the &lt;a class="link" href="http://subversion.tigris.org/" title="svn"&#10; target="_blank" rel="noopener"&#10; &gt;SVN&lt;/a&gt; Server to configure a hook. What do you do ?&lt;/p&gt;&#10;&lt;p&gt;Assuming you are using &lt;a class="link" href="http://tortoisesvn.tigris.org/" title="tortoisesvn"&#10; target="_blank" rel="noopener"&#10; &gt;TortoiseSVN&lt;/a&gt;, you can configure a &lt;a class="link" href="http://tortoisesvn.tigris.org/tsvn_1.5_releasenotes.html#client-side-hooks" title="tortoisesvn-client-side-hook"&#10; target="_blank" rel="noopener"&#10; &gt;Client-Side hook&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;Here is an example - Say you want to abort commit if you have a comment in your code that starts with &lt;strong&gt;//Do Not Commit&lt;/strong&gt;. You can create a &lt;a class="link" href="http://en.wikipedia.org/wiki/Windows_PowerShell" title="wikipedia-powershell"&#10; target="_blank" rel="noopener"&#10; &gt;PowerShell&lt;/a&gt; script that validates all the files in your changeset and use this script as a Client-Side pre_commit_hook in TortoiseSVN.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/TortoiseSVN-Settings-HookScripts.png"&#10;&#9;&#9;&#9;alt="TortoiseSVN-Settings-HookScripts"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;TortoiseSVN-Settings-HookScripts&lt;/p&gt;&#10;&#9;&#9;&lt;/figcaption&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;The pre_commit_hook configuration :&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/Configure-Hook-Scripts.png"&#10;&#9;&#9;&#9;alt="Configure-Hook-Scripts"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;Configure-Hook-Scripts&lt;/p&gt;&#10;&#9;&#9;&lt;/figcaption&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;//Powershell script : pre_commit.ps1&lt;/p&gt;&#10;&lt;p&gt;$donotcommit = &amp;ldquo;//Do Not Commit&amp;rdquo;;&lt;/p&gt;&#10;&lt;p&gt;$changeset = Get-Content$args[0];&lt;/p&gt;&#10;&lt;p&gt;foreach($file in $changeset)&#10;{&#10;if( Get-Content$file | Select-String$donotcommit-quiet )&#10;{&#10;Write-Error &amp;ldquo;$file contains code that you are not supposed to commit. [$donotcommit]&amp;rdquo;;&#10;exit9;&#10;}&#10;}&lt;/p&gt;&#10;&lt;p&gt;Now, if your changeset has a file with a comment starting with &lt;strong&gt;//Do Not Commit&lt;/strong&gt; and you click on OK to commit this change, the commit will be aborted with this error message -&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/pre_commit_hook-validation1.png"&#10;&#9;&#9;&#9;alt="pre_commit_hook-validation"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;pre_commit_hook-validation&lt;/p&gt;&#10;&#9;&#9;&lt;/figcaption&gt;&#10;&lt;/figure&gt;&#10;&#10;</description></item></channel></rss>