Skip to content

Commit fde80a3

Browse files
committed
Merge branch 'master' of https://github.com/TheSnoozer/maven-git-commit-id-plugin into TheSnoozer-master
Conflicts: src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java
2 parents 6b49562 + 60cb978 commit fde80a3

File tree

6 files changed

+54
-418
lines changed

6 files changed

+54
-418
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ It's really simple to setup this plugin; below is a sample pom that you may base
215215

216216
<!-- when the build is triggered while the repo is in "dirty state", append this suffix -->
217217
<dirty>-dirty</dirty>
218-
218+
219+
<!-- Only consider tags matching the given pattern. This can be used to avoid leaking private tags from the repository. -->
220+
<match>*</match>
221+
219222
<!--
220223
always print using the "tag-commits_from_tag-g_commit_id-maybe_dirty" format, even if "on" a tag.
221224
The distance will always be 0 if you're "on" the tag.
@@ -535,20 +538,25 @@ Optional parameters:
535538
* **dateFormat** - `(default: dd.MM.yyyy '@' HH:mm:ss z)` is a normal SimpleDateFormat String and will be used to represent git.build.time and git.commit.time
536539
* **verbose** - `(default: false)` if true the plugin will print a summary of all collected properties when it's done
537540
* **generateGitPropertiesFile** -`(default: false)` this is false by default, forces the plugin to generate the git.properties file
538-
* **generateGitPropertiesFilename** - `(default: src/main/resources/git.properties)` - The path for the to be generated properties file, it's relative to ${project.basedir}
541+
* **generateGitPropertiesFilename** - `(default: ${project.build.outputDirectory}/git.properties)` - The path for the to be generated properties file. The path can be relative to ${project.basedir} (e.g. target/classes/git.properties) or can be a full path (e.g. ${project.build.outputDirectory}/git.properties).
539542
* **skipPoms** - `(default: true)` - Force the plugin to run even if you're inside of an pom packaged project.
540543
* **failOnNoGitDirectory** - `(default: true)` *(available since v2.0.4)* - Specify whether the plugin should fail when a .git directory can not be found. When set to false and no .git directory is found the plugin will skip execution.
544+
* **failOnUnableToExtractRepoInfo** - `(default: true)` By default the plugin will fail the build if unable to obtain enough data for a complete run, if you don't care about this, you may want to set this value to false.
541545
* **skip** - `(default: false)` *(available since v2.1.8)* - Skip the plugin execution completely.
542546
* **excludeProperties** - `(default: empty)` *(available since v2.1.9)* - Allows to filter out properties that you *don't* want to expose. This feature was implemented in response to [this issue](https://github.com/ktoso/maven-git-commit-id-plugin/issues/91), so if you're curious about the use-case, check that issue.
543547
* **useNativeGit** - `(default: false)` *(available since v2.1.10)* - Uses the native `git` binary instead of the custom `jgit` implementation shipped with this plugin to obtain all information. Although this should usualy give your build some performance boost, it may randomly break if you upgrade your git version and it decides to print information in a different format suddenly. As rule of thumb, keep using the default `jgit` implementation (keep this option set to `false`) until you notice performance problems within your build (usualy when you have *hundreds* of maven modules).
548+
* **abbrevLength** - `(default: 7)` Configure the "git.commit.id.abbrev" property to be at least of length N (see gitDescribe abbrev for special case abbrev = 0).
549+
* **format** - `(default: properties)` The format to save properties in. Valid options are "properties" (default) and "json". Properties will be saved to the generateGitPropertiesFilename if generateGitPropertiesFile is set to `true`.
550+
544551

545552
**gitDescribe**:
546553
Worth pointing out is, that git-commit-id tries to be 1-to-1 compatible with git's plain output, even though the describe functionality has been reimplemented manually using JGit (you don't have to have a git executable to use the plugin). So if you're familiar with [git-describe](https://github.com/ktoso/maven-git-commit-id-plugin#git-describe---short-intro-to-an-awesome-command), you probably can skip this section, as it just explains the same options that git provides.
547554

548555
* **abbrev** - `(default: 7)` in the describe output, the object id of the hash is always abbreviated to N letters, by default 7. The typical describe output you'll see therefore is: `v2.1.0-1-gf5cd254`, where `-1-` means the number of commits away from the mentioned tag and the `-gf5cd254` part means the first 7 chars of the current commit's id `f5cd254`. **Please note that the `g` prefix is included to notify you that it's a commit id, it is NOT part of the commit's object id** - *this is default git bevaviour, so we're doing the same*. You can set this to any value between 0 and 40 (inclusive).
549556
* **abbrev = 0** is a special case. Setting *abbrev* to `0` has the effect of hiding the "distance from tag" and "object id" parts of the output, so you endup with just the "nearest tag" (that is, instead `tag-12-gaaaaaaa` with `abbrev = 0` you'd get `tag`).
550557
* **dirty** - `(default: "")` when you run describe on a repository that's in "dirty state" (has uncommited changes), the describe output will contain an additional suffix, such as "-devel" in this example: `v3.5-3-g2222222-devel`. You can configure that suffix to be anything you want, "-DEV" being a nice example. The "-" sign should be inclided in the configuration parameter, as it will not be added automatically. If in doubt run `git describe --dirty=-my_thing` to see how the end result will look like.
551-
* **tags** - `(default: false)`
558+
* **tags** - `(default: false)` if true this option enables matching a lightweight (non-annotated) tag.
559+
* **match** - `(default: *)` only consider tags matching the given pattern (can be used to avoid leaking private tags made from the repository)
552560
* **long** - `(default: false)` git-describe, by default, returns just the tag name, if the current commit is tagged. Use this option to force it to format the output using the typical describe format. An example would be: `tagname-0-gc0ffebabe` - notice that the distance from the tag is 0 here, if you don't use **forceLongFormat** mode, the describe for such commit would look like this: `tagname`.
553561
* **always** - `(default: true)` if unable to find a tag, print out just the object id of the current commit. Useful when you always want to return something meaningful in the describe property.
554562
* **skip** - `(default: false)` when you don't use `git-describe` information in your build, you can opt to be calculate it.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
<!--<skip>false</skip>-->
217217
<!--<always>false</always>-->
218218
<!--<abbrev>7</abbrev>-->
219+
<!--<match>*</match>-->
219220
<!--<dirty>-DEVEL</dirty>-->
220221
<!--<forceLongFormat>false</forceLongFormat>-->
221222
<!--</gitDescribe>-->

src/main/java/pl/project13/maven/git/GitDescribeConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ public class GitDescribeConfig {
148148
* since tag v1.2 that points at object deadbee....).
149149
*
150150
* <pre>false</pre> by default.
151+
*
152+
* @parameter default-value=false
151153
*/
152154
private boolean forceLongFormat;
153155

src/main/java/pl/project13/maven/git/NativeGitProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,16 @@ private String getArgumentsForGitDescribeAndDescibeNotNull(GitDescribeConfig git
139139

140140
String dirtyMark = gitDescribe.getDirty();
141141
if (dirtyMark != null && !dirtyMark.isEmpty()) {
142-
// Option: --dirty[=<mark>]
143142
// TODO: Code Injection? Or does the CliRunner escape Arguments?
144143
argumentsForGitDescribe.append("--dirty=" + dirtyMark + " ");
145144
}
146145

146+
String matchOption = gitDescribe.getMatch();
147+
if (matchOption != null && !matchOption.isEmpty()) {
148+
// TODO: Code Injection? Or does the CliRunner escape Arguments?
149+
argumentsForGitDescribe.append("--match=" + matchOption + " ");
150+
}
151+
147152
argumentsForGitDescribe.append("--abbrev=" + gitDescribe.getAbbrev() + " ");
148153

149154
if (gitDescribe.getTags()) {

src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,40 @@ public void shouldExtractTagsOnGivenCommit(boolean useNativeGit) throws Exceptio
599599
.containsOnly("lightweight-tag", "newest-tag");
600600
}
601601

602+
@Test
603+
@Parameters(method = "useNativeGit")
604+
public void runGitDescribeWithMatchOption(boolean useNativeGit) throws Exception {
605+
// given
606+
mavenSandbox.withParentProject("my-pom-project", "pom")
607+
.withChildProject("my-jar-module", "jar")
608+
.withGitRepoInChild(AvailableGitTestRepo.MAVEN_GIT_COMMIT_ID_PLUGIN)
609+
.create(CleanUp.CLEANUP_FIRST);
610+
MavenProject targetProject = mavenSandbox.getChildProject();
611+
612+
setProjectToExecuteMojoIn(targetProject);
613+
614+
Map<String,String> gitTagMap = new HashMap<String,String>();
615+
gitTagMap.put("v2.1.8", "4f787aa37d5d9c06780278f0cf92553d304820a2");
616+
gitTagMap.put("v2.1.9", "a9dba4a25b64ab288d90cd503785b830d2e189a2");
617+
618+
for (Map.Entry<String,String> entry : gitTagMap.entrySet()) {
619+
String gitDescribeMatchNeedle = entry.getKey();
620+
String commitIdOfMatchNeedle = entry.getValue();
621+
622+
GitDescribeConfig gitDescribeConfig = new GitDescribeConfig();
623+
gitDescribeConfig.setMatch(gitDescribeMatchNeedle);
624+
alterMojoSettings("gitDescribe", gitDescribeConfig);
625+
alterMojoSettings("useNativeGit", useNativeGit);
626+
627+
// when
628+
mojo.execute();
629+
630+
// then
631+
assertThat(targetProject.getProperties()).includes(entry("git.commit.id.describe", gitDescribeMatchNeedle));
632+
assertThat(targetProject.getProperties().get("git.commit.id")).isNotEqualTo(commitIdOfMatchNeedle);
633+
}
634+
}
635+
602636
private GitDescribeConfig createGitDescribeConfig(boolean forceLongFormat, int abbrev) {
603637
GitDescribeConfig gitDescribeConfig = new GitDescribeConfig();
604638
gitDescribeConfig.setTags(true);

0 commit comments

Comments
 (0)