mirror of
https://github.com/linkedin/school-of-sre
synced 2026-01-14 04:28:02 +00:00
Deployed 52e7ed5 with MkDocs version: 1.1.2
This commit is contained in:
@@ -1281,23 +1281,23 @@
|
||||
</ul>
|
||||
<h2 id="hooks">Hooks</h2>
|
||||
<p>Git has another nice feature called hooks. Hooks are basically scripts which will be called when a certain event happens. Here is where hooks are located:</p>
|
||||
<div class="highlight"><pre><span></span><code>$ ls .git/hooks/
|
||||
<pre><code class="language-bash">$ ls .git/hooks/
|
||||
applypatch-msg.sample fsmonitor-watchman.sample pre-applypatch.sample pre-push.sample pre-receive.sample update.sample
|
||||
commit-msg.sample post-update.sample pre-commit.sample pre-rebase.sample prepare-commit-msg.sample
|
||||
</code></pre></div>
|
||||
</code></pre>
|
||||
<p>Names are self explanatory. These hooks are useful when you want to do certain things when a certain event happens. If you want to run tests before pushing code, you would want to setup <code>pre-push</code> hooks. Let's try to create a pre commit hook.</p>
|
||||
<div class="highlight"><pre><span></span><code>$ <span class="nb">echo</span> <span class="s2">"echo this is from pre commit hook"</span> > .git/hooks/pre-commit
|
||||
<pre><code class="language-bash">$ echo "echo this is from pre commit hook" > .git/hooks/pre-commit
|
||||
$ chmod +x .git/hooks/pre-commit
|
||||
</code></pre></div>
|
||||
</code></pre>
|
||||
<p>We basically create a file called <code>pre-commit</code> in hooks folder and make it executable. Now if we make a commit, we should see the message getting printed.</p>
|
||||
<div class="highlight"><pre><span></span><code>$ <span class="nb">echo</span> <span class="s2">"sample file"</span> > sample.txt
|
||||
<pre><code class="language-bash">$ echo "sample file" > sample.txt
|
||||
$ git add sample.txt
|
||||
$ git commit -m <span class="s2">"adding sample file"</span>
|
||||
this is from pre commit hook <span class="c1"># <===== THE MESSAGE FROM HOOK EXECUTION</span>
|
||||
<span class="o">[</span>master 9894e05<span class="o">]</span> adding sample file
|
||||
<span class="m">1</span> file changed, <span class="m">1</span> insertion<span class="o">(</span>+<span class="o">)</span>
|
||||
create mode <span class="m">100644</span> sample.txt
|
||||
</code></pre></div>
|
||||
$ git commit -m "adding sample file"
|
||||
this is from pre commit hook # <===== THE MESSAGE FROM HOOK EXECUTION
|
||||
[master 9894e05] adding sample file
|
||||
1 file changed, 1 insertion(+)
|
||||
create mode 100644 sample.txt
|
||||
</code></pre>
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user