Skip to content

Commit 399b9bb

Browse files
committed
Empty prefix setting should not keep the leading "."
Resolves #101
1 parent 544a4b7 commit 399b9bb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ public void execute() throws MojoExecutionException {
302302

303303
try {
304304
properties = initProperties();
305-
prefixDot = prefix + ".";
305+
306+
String trimmedPrefix = prefix.trim();
307+
prefixDot = trimmedPrefix.equals("") ? "" : trimmedPrefix + ".";
306308

307309
loadGitData(properties);
308310
loadBuildTimeData(properties);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ public void shouldExcludeAsConfiguredProperties() throws Exception {
111111
verify(mojo).putGitDescribe(any(Properties.class), any(Repository.class));
112112
}
113113

114+
115+
@Test
116+
public void shouldHaveNoPrefixWhenConfiguredPrefixIsEmptyStringAsConfiguredProperties() throws Exception {
117+
// given
118+
mojo.setPrefix("");
119+
120+
// when
121+
mojo.execute();
122+
123+
// then
124+
Properties properties = mojo.getProperties();
125+
126+
// explicitly excluded
127+
assertThat(properties).satisfies(new DoesNotContainKeyCondition("git.remote.origin.url"));
128+
assertThat(properties).satisfies(new DoesNotContainKeyCondition(".remote.origin.url"));
129+
assertThat(properties).satisfies(new ContainsKeyCondition("remote.origin.url"));
130+
}
131+
114132
@Test
115133
public void shouldSkipDescribeWhenConfiguredToDoSo() throws Exception {
116134
// given

0 commit comments

Comments
 (0)