git-commit-id-maven-plugin
git-commit-id-maven-plugin copied to clipboard
Not possible to disable `-dirty` suffix completely
It doesn't seem to be possible to disable or set a zero length string for the dirty
suffix.
I'm guessing this is because the plugin conflates an empty string with the default value, and also maven whitespace stripping is a consideration.
Current Behavior
Setting <dirty></dirty>
still creates the dirty suffix on the git.commit.id.describe
output.
Steps to Reproduce (for bugs only)
- Add untracked file to repo, check git describe:
git describe --dirty
->1.0.0-dirty
- Attempt to disable dirty suffix with an empty string in config:
<gitDescribe>
<dirty></dirty>
</gitDescribe>
- Output of
git.commit.id.describe
still includes dirty suffix.
Environment (for bugs only)
Plugin: 2.2.4 Maven 3.3.9
Hi, thanks for reporting your issue here. This might be related to https://issues.apache.org/jira/browse/MNG-5725 and https://issues.apache.org/jira/browse/MNG-6434
if it is, which I suspect there is not much I can do (its a maven bug). I'll look into it.
For now I would suggest to use a workaround with replacementProperties
<replacementProperties>
<replacementProperty>
<property>git.commit.id.describe</property>
<propertyOutputSuffix>withoutdirty</propertyOutputSuffix>
<token>^(.*)(-dirty)?$</token>
<value>$1</value>
</replacementProperty>
</replacementProperties>
Note: I haven't tested it yet....but should be close to what it should look like.
Hi, thanks for reporting your issue here. This might be related to https://issues.apache.org/jira/browse/MNG-5725 and https://issues.apache.org/jira/browse/MNG-6434
if it is, which I suspect there is not much I can do (its a maven bug). I'll look into it.
For now I would suggest to use a workaround with replacementProperties
<replacementProperties> <replacementProperty> <property>git.commit.id.describe</property> <propertyOutputSuffix>withoutdirty</propertyOutputSuffix> <token>^(.*)(-dirty)?$</token> <value>$1</value> </replacementProperty> </replacementProperties>
Note: I haven't tested it yet....but should be close to what it should look like.
Unfortunate this regex don't work for me :C
I use this:
<replacementProperties>
<replacementProperty>
<property>git.commit.id.describe</property>
<token>^([\d\.]*)(-)?([\d]*)?(-)?(g[\w]*)?(-dirty)?$</token>
<value>$1$2$3$4$5</value>
</replacementProperty>
</replacementProperties>
Thanks for the follow up!
As mentioned I never tested this, but you are right my suggestion does not seem to work since .*
is the greedy regex version.
Using the non-greedy version (https://regex101.com/r/zANtrm/1) like ^(.*?)(-dirty)?$
should do the trick.
Tests yield:
[echo] ===========================================================================
[echo] git.commit.id.describe: git-commit-id-plugin-debugging-0.0.2-9-gcad3d4a-dirty
[echo] git.commit.id.describe.withoutdirty: git-commit-id-plugin-debugging-0.0.2-9-gcad3d4a
[echo] ===========================================================================
[echo] git.commit.id.describe: git-commit-id-plugin-debugging-0.0.2-9-gbeef4e9
[echo] git.commit.id.describe.withoutdirty: git-commit-id-plugin-debugging-0.0.2-9-gbeef4e9
Note there does not seem to be a difference between the <token>^(.*?)(-dirty)?$</token>
and <token>^(.*?)-dirty$</token>
...however I guess the first would is "nicer".
Also this should be possible to use lookahead or lookbehind regex versions....not entirely sure which would be the fastest....
Full config:
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>${git-commit-id-version}</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
<execution>
<id>validate-the-git-infos</id>
<goals>
<goal>validateRevision</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<prefix>git</prefix>
<skipPoms>false</skipPoms>
<verbose>false</verbose>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<injectAllReactorProjects>true</injectAllReactorProjects>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<evaluateOnCommit>HEAD</evaluateOnCommit>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<replacementProperties>
<replacementProperty>
<property>git.commit.id.describe</property>
<propertyOutputSuffix>withoutdirty</propertyOutputSuffix>
<token>^(.*?)(-dirty)?$</token>
<value>$1</value>
</replacementProperty>
</replacementProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<echo>===========================================================================</echo>
<echo>git.commit.id.describe: ${git.commit.id.describe}</echo>
<echo>git.commit.id.describe.withoutdirty: ${git.commit.id.describe.withoutdirty}</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Thanks for the follow up! As mentioned I never tested this, but you are right my suggestion does not seem to work since
.*
is the greedy regex version.Using the non-greedy version (https://regex101.com/r/zANtrm/1) like
^(.*?)(-dirty)?$
should do the trick.Tests yield:
[echo] =========================================================================== [echo] git.commit.id.describe: git-commit-id-plugin-debugging-0.0.2-9-gcad3d4a-dirty [echo] git.commit.id.describe.withoutdirty: git-commit-id-plugin-debugging-0.0.2-9-gcad3d4a [echo] =========================================================================== [echo] git.commit.id.describe: git-commit-id-plugin-debugging-0.0.2-9-gbeef4e9 [echo] git.commit.id.describe.withoutdirty: git-commit-id-plugin-debugging-0.0.2-9-gbeef4e9
Note there does not seem to be a difference between the
<token>^(.*?)(-dirty)?$</token>
and<token>^(.*?)-dirty$</token>
...however I guess the first would is "nicer".Also this should be possible to use lookahead or lookbehind regex versions....not entirely sure which would be the fastest....
Full config:
<plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> <version>${git-commit-id-version}</version> <executions> <execution> <id>get-the-git-infos</id> <goals> <goal>revision</goal> </goals> <phase>initialize</phase> </execution> <execution> <id>validate-the-git-infos</id> <goals> <goal>validateRevision</goal> </goals> <phase>compile</phase> </execution> </executions> <configuration> <prefix>git</prefix> <skipPoms>false</skipPoms> <verbose>false</verbose> <dotGitDirectory>${project.basedir}/.git</dotGitDirectory> <injectAllReactorProjects>true</injectAllReactorProjects> <generateGitPropertiesFile>true</generateGitPropertiesFile> <evaluateOnCommit>HEAD</evaluateOnCommit> <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename> <replacementProperties> <replacementProperty> <property>git.commit.id.describe</property> <propertyOutputSuffix>withoutdirty</propertyOutputSuffix> <token>^(.*?)(-dirty)?$</token> <value>$1</value> </replacementProperty> </replacementProperties> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.8</version> <executions> <execution> <phase>package</phase> <configuration> <target> <echo>===========================================================================</echo> <echo>git.commit.id.describe: ${git.commit.id.describe}</echo> <echo>git.commit.id.describe.withoutdirty: ${git.commit.id.describe.withoutdirty}</echo> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
It worked like charm 👍