{"id":6543,"date":"2018-12-09T14:51:21","date_gmt":"2018-12-09T14:51:21","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=6543"},"modified":"2022-01-27T13:15:38","modified_gmt":"2022-01-27T13:15:38","slug":"pre-commit-hooks-in-git","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/pre-commit-hooks-in-git\/","title":{"rendered":"Creating a pre-commit hook for TortoiseGit"},"content":{"rendered":"<p><em>Note: This is specific to using TortoiseGit to add your hooks.<\/em><\/p>\n<p>I&#8217;ve covered <a href=\"http:\/\/putridparrot.com\/blog\/creating-a-pre-commit-hook-for-tortoisesvn\/\" rel=\"noopener\" target=\"_blank\">Creating a pre-commit hook for TortoiseSvn<\/a> previously for SVN. We can create similar hooks for GIT also.<\/p>\n<p>Either create a script or other form of executable (this one&#8217;s a C# console application). This example is going to do nothing of real interest. It&#8217;ll simply stop commits to a repo. but is useful if we place a <em>Debugger.Break<\/em> before the Console line, for debugging purposes<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nstatic int Main(string&#x5B;] args)\r\n{\r\n   Console.Error.WriteLine(&quot;No commits allowed&quot;);\r\n   return 1;\r\n}\r\n<\/pre>\n<p>A non-zero return value indicates a failure and hence this code will effectively stop any commits to the repository it&#8217;s applied to.<\/p>\n<p>The arguments sent to the method will be as follows<\/p>\n<p>* 1st arg is the file name of a file which contains a list of files that have changed<br \/>\n* 2nd arg is the file name of a file which has the commit message<br \/>\n* 3rd arg is the folder being committed<\/p>\n<p>Now we compile our application and place it in the .git\\hooks\\ folder and we need to name it <strong>pre-commit.exe<\/strong>.<\/p>\n<p>That&#8217;s all there is to it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: This is specific to using TortoiseGit to add your hooks. I&#8217;ve covered Creating a pre-commit hook for TortoiseSvn previously for SVN. We can create similar hooks for GIT also. Either create a script or other form of executable (this one&#8217;s a C# console application). This example is going to do nothing of real interest. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[206],"tags":[],"class_list":["post-6543","post","type-post","status-publish","format-standard","hentry","category-git-2"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=6543"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6543\/revisions"}],"predecessor-version":[{"id":9110,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6543\/revisions\/9110"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=6543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=6543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=6543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}