Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get total number of count for git tags

I want to get the total number of tag count in a repository

The grgit repository already solves the problem.

git = org.ajoberstar.grgit.Grgit.open()
git.tag.list().size()

But its in groovy and I want a gradle version of it.

git describe --tags $(git rev-list --tags --count)

Above code gives total number of commits

I have the following snippet so far which gets the total number of commits.

versionCode = { ->
    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
    }
}

I have referenced this SO question but without proper answer

like image 320
Rinav Avatar asked Dec 24 '22 00:12

Rinav


1 Answers

If you don't mind using commands besides git... git tag | wc -l

like image 175
EncryptedWatermelon Avatar answered Dec 26 '22 11:12

EncryptedWatermelon