title: How to get total number of count for git tags
body: <p>I want to get the total number of tag count in a repository</p>
  
  <p>The <a href="https://github.com/ajoberstar/grgit" rel="noreferrer">grgit</a> repository already solves the problem. </p>
  
  <pre><code>git = org.ajoberstar.grgit.Grgit.open()
  git.tag.list().size()
  </code></pre>
  
  <p>But its in groovy and I want a gradle version of it.</p>
  
  <pre><code>git describe --tags $(git rev-list --tags --count)
  </code></pre>
  
  <p>Above code gives total number of commits</p>
  
  <p>I have the following snippet so far which gets the total number of commits.</p>
  
  <pre><code>versionCode = { -&gt;
      try {
          def stdout = new ByteArrayOutputStream()
          exec {
              commandLine 'git', 'rev-list', '--first-parent', '--count', 'HEAD'
              standardOutput = stdout
          }
          return Integer.parseInt(stdout.toString().trim())
      }
      catch (ignored) {
          return -1
      }
  }
  </code></pre>
  
  <p>I have referenced <a href="https://stackoverflow.com/q/17097263/1336154">this SO question</a> but without proper answer</p>