Maven git describe without tags

349 Views Asked by At

We're using the Maven plugin git-commit-id-maven-plugin and want to make both hash and dirty status available to our build. Our plugin:

<plugin>
    <groupId>io.github.git-commit-id</groupId>
    <artifactId>git-commit-id-maven-plugin</artifactId>
    <version>5.0.0</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
            <phase>validate</phase>
        </execution>
    </executions>
</plugin>

E.g. we have a filtered properties file with:

git=${git.commit.id.describe}

However this describe-variant cares about tags, which we do not want into our usage of it. If doing this from terminal I see from other questions and answers that this is easily done.

E.g. ${git.commit.id.describe} might return:

mytag-hash-dirty

Our ideal result would be only:

hash-dirty

How can I achieve the "hash and dirty status"-only result using the git-commit-id-maven-plugin with Maven?

1

There are 1 best solutions below

0
Halvor Holsten Strand On BEST ANSWER

I ended up using the following configuration of the plugin:

<plugin>
    <groupId>io.github.git-commit-id</groupId>
    <artifactId>git-commit-id-maven-plugin</artifactId>
    <version>5.0.0</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
            <phase>validate</phase>
        </execution>
    </executions>
    <configuration>
        <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
        <gitDescribe>
            <match>!*</match>
        </gitDescribe>
    </configuration>
</plugin>

Where we only include/consider tags that match the !* pattern. This works in tandem with always being true (which happens to be the default). This should be fairly equivalent to the following command:

git describe --abbrev=7 --always --match='!*' --dirty

This gives the desired result when using the ${git.commit.id.describe} variable.