title: Makefile target to check for clean git diff
body: <p>I am trying to write a <code>Makefile</code> target that checks for no uncomitted changes in the git repository where it is ran after running another target.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>check-git-clean: other-target
  ifneq ($(shell git diff-index --quiet HEAD; echo $$?), 0)
      $(error "There are uncomitted changes after running make other-target")
  endif
  </code></pre>
  
  <p>However, what I am experiencing is that if the <code>other-target</code> causes uncommitted changes, the <code>ifneq</code> will not catch it. On the other hand, if there were already uncommitted changes <em>before</em> I run <code>make check-git-clean</code>, then the <code>ifneq</code> does catch it.</p>
  
  <p>So, in a way, it's almost as if the <code>ifneq</code> is running "before" the <code>make other-target</code> but the CLI output (echo) I get are in the right order.</p>
  
  <p>I'm wondering how I can do this right.</p>