Repository: git-commit-id/git-commit-id-maven-plugin

Issue #374: Not possible to disable `-dirty` suffix completely
Created: 2018-08-09T10:10:39Z
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

Duplicate issue #490: incorrect --dirty default
Created: 2020-06-05T15:07:36Z
Describe the bug
If the --dirty flag is not set, then "-dirty" should not be appended to the git describe output.
Steps to Reproduce
Add this to POM to echo result of git describe
    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.8</version>
      <executions>
        <execution>
          <phase>initialize</phase>
          <configuration>
            <target>
              <echo>Git-Infos: ${git.commit.id.describe-short}</echo>
            </target>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
make sure the repo is dirty.
mvn validate
output:      [echo] Git-Infos: 2.0.0-dirty
config of plugin:
                <plugin>
                    <groupId>pl.project13.maven</groupId>
                    <artifactId>git-commit-id-plugin</artifactId>
                    <version>4.0.0</version>
                    <executions>
                        <execution>
                            <id>get-the-git-infos</id>
                            <goals>
                                <goal>revision</goal>
                            </goals>
                            <phase>validate</phase>
                        </execution>
                    </executions>
                    <configuration>
                        <generateGitPropertiesFile>false</generateGitPropertiesFile>
                        <gitDescribe>
                            <tags>true</tags>
                        </gitDescribe>
                    </configuration>
                </plugin>
Expected behavior
"-dirty" should not be appended to output.
Additional context
this was introduced in 2.13.0  here  #149
quote from issue:

Sorry for this second post, but man git-describe told me the default:
 OPTIONS --dirty[=<mark>] Describe the working tree. It means describe HEAD and appends <mark> (-dirty by default) if the working tree is dirty.
so this is not a problem with defaults, this is a problem not folling the man pages :)

This interpretation of the man page is simply not correct IMO.
--dirty can be used as a flag without specifying the optional "=mark" . in which case the default is in fact to append "-dirty".
however if the --dirty flags is not set at all, then no dirty mark should be appended.
the part of the man page stating

appends  (-dirty by default)

is only referring to the default value of the mark, not whether it is default to even include the mark.
git help:
usage: git describe [<options>] [<commit-ish>...]
   or: git describe [<options>] --dirty

    --contains            find the tag that comes after the commit
    --debug               debug search strategy on stderr
    --all                 use any ref
    --tags                use any tag, even unannotated
    --long                always use long format
    --first-parent        only follow first parent
    --abbrev[=<n>]        use <n> digits to display SHA-1s
    --exact-match         only output exact matches
    --candidates <n>      consider <n> most recent tags (default: 10)
    --match <pattern>     only consider tags matching <pattern>
    --exclude <pattern>   do not consider tags matching <pattern>
    --always              show abbreviated commit object as fallback
    --dirty[=<mark>]      append <mark> on dirty working tree (default: "-dirty")
    --broken[=<mark>]     append <mark> on broken working tree (default: "-broken")

In any case, if you wish to keep the current defaults, then at least I need a way to unset the --dirty flag which does not seem possible atm.

Closing comment (2020-06-07T21:38:15Z): Hi, thank you for creating this issue!
In short you are most likely right (e.g. a git describe doesn't have a dirty flag when the status is dirty) however I think the situation from the perspective from the plugin is a bit more tricky and is related to #374.
In a nutshell I'm not aware that maven offers to set an empty value for a configuration (e.g. disable the dirty flag output), however you could get away with the workaround described in #374 (comment).
From my perspective it is not a problem of the default, it is a problem how the plugin assumes things to be. Back when the logic was introduced the plugin assumed that users run git describe --dirty which uses the default dirty-mark (as outlined in the documentation you copied). As a result I think the flaw is not the interpretation of the default, it is a flaw in the plugin that one can not disable the -dirty-flag or run simply git describe.
Now as solution we have possible ways:

the workaround described in #374 (comment)
introduce another flag (excludeDirtyFlag) that indicates if a user wants a dirty-mark at all (perhaps the best alternative). If set to true that would mean that even if a user sets the <dirty>fooobar</dirty> it would get ignored (IMHO that would be the downside of this, since one switch overrides the other)
wait for maven to fix the issue (not very likely)

As may can extract from the possible solutions: I would not change the behaviour which would break backward compatibility - I'd rather introduce some mechanism to achieve what is desired.