Skip to content

Commit 1ad9691

Browse files
authored
Merge pull request #95 from ericmaino/fix-version-version
Fixes describe.tag.version.version.label
2 parents 0df8c36 + 72fe13f commit 1ad9691

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
build/
33
.idea/
44
out/
5+
bin/

src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ private Map<String, Supplier<String>> generateGlobalFormatPlaceholderMap(GitSitu
575575
placeholderMap.put("describe.tag.version.patch", Lazy.by(() -> notNullOrDefault(descriptionTagVersionMatcher.get().group("patch"), "0")));
576576
placeholderMap.put("describe.tag.version.patch.next", Lazy.by(() -> increase(placeholderMap.get("describe.tag.version.patch").get(), 1)));
577577

578-
placeholderMap.put("describe.tag.version.version.label", Lazy.by(() -> notNullOrDefault(descriptionTagVersionMatcher.get().group("label"), "")));
578+
placeholderMap.put("describe.tag.version.label", Lazy.by(() -> notNullOrDefault(descriptionTagVersionMatcher.get().group("label"), "")));
579579
placeholderMap.put("describe.tag.version.label.next", Lazy.by(() -> increase(placeholderMap.get("describe.tag.version.label").get(), 1)));
580580

581581
final Lazy<Integer> descriptionDistance = Lazy.by(() -> description.get().getDistance());
@@ -584,7 +584,7 @@ private Map<String, Supplier<String>> generateGlobalFormatPlaceholderMap(GitSitu
584584
placeholderMap.put("describe.tag.version.patch.plus.describe.distance", Lazy.by(() -> increase(placeholderMap.get("describe.tag.version.patch").get(), descriptionDistance.get() )));
585585
placeholderMap.put("describe.tag.version.patch.next.plus.describe.distance", Lazy.by(() -> increase(placeholderMap.get("describe.tag.version.patch.next").get(), descriptionDistance.get())));
586586

587-
placeholderMap.put("describe.tag.version.label.plus.describe.distance", Lazy.by(() -> increase(placeholderMap.get("describe.tag.version.version.label").get(), descriptionDistance.get())));
587+
placeholderMap.put("describe.tag.version.label.plus.describe.distance", Lazy.by(() -> increase(placeholderMap.get("describe.tag.version.label").get(), descriptionDistance.get())));
588588
placeholderMap.put("describe.tag.version.label.next.plus.describe.distance", Lazy.by(() -> increase(placeholderMap.get("describe.tag.version.label.next").get(), descriptionDistance.get())));
589589

590590
// command parameters e.g. gradle -Pfoo=123 will be available as ${property.foo}

src/test/java/me/qoomon/gradle/gitversioning/GitVersioningPluginTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,32 @@ void apply_TwoCommitsSinceLastTagGivesExpectedPlusDistanceResult() throws GitAPI
293293
// then
294294
assertThat(project.getVersion()).isEqualTo("679");
295295
}
296+
297+
@Test
298+
void apply_CommitWithLabelTagGivesExpectedLabel() throws GitAPIException, IOException {
299+
// given
300+
Git git = Git.init().setInitialBranch(MASTER).setDirectory(projectDir.toFile()).call();
301+
git.commit().setMessage("initial commit").setAllowEmpty(true).call();
302+
String givenTag = "2.0.4-677-SNAPSHOT";
303+
git.tag().setName(givenTag).call();
304+
305+
Project project = ProjectBuilder.builder().withProjectDir(projectDir.toFile()).build();
306+
307+
project.getPluginManager().apply(GitVersioningPlugin.class);
308+
309+
GitVersioningPluginExtension extension = (GitVersioningPluginExtension) project.getExtensions()
310+
.getByName("gitVersioning");
311+
312+
GitVersioningPluginConfig config = new GitVersioningPluginConfig() {{
313+
refs.branch(".*", patch -> {
314+
patch.version = "${describe.tag.version.label}";
315+
});
316+
}};
317+
318+
// when
319+
extension.apply(config);
320+
321+
// then
322+
assertThat(project.getVersion()).isEqualTo("677-SNAPSHOT");
323+
}
296324
}

0 commit comments

Comments
 (0)