From 98f7bb63b0751855206688c069c7563824f4a7c8 Mon Sep 17 00:00:00 2001 From: Benjamin Dean Date: Tue, 9 Feb 2016 22:13:12 -0500 Subject: [PATCH] use project dir in getGitVersion rather than running `git describe` in the current working dir, run it in the directory of the gradle project. This allows projects that come from git submodules to use the versions from their tags. --- .../com/cinnober/gradle/semver_git/SemverGitPlugin.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/groovy/com/cinnober/gradle/semver_git/SemverGitPlugin.groovy b/src/main/groovy/com/cinnober/gradle/semver_git/SemverGitPlugin.groovy index 5c20677..380953f 100644 --- a/src/main/groovy/com/cinnober/gradle/semver_git/SemverGitPlugin.groovy +++ b/src/main/groovy/com/cinnober/gradle/semver_git/SemverGitPlugin.groovy @@ -29,13 +29,13 @@ import org.gradle.api.Plugin class SemverGitPlugin implements Plugin { - def static String getGitVersion(String nextVersion, String snapshotSuffix) { - def proc = "git describe --exact-match".execute(); + def static String getGitVersion(String nextVersion, String snapshotSuffix, File projectDir = null) { + def proc = "git describe --exact-match".execute(null, projectDir); proc.waitFor(); if (proc.exitValue() == 0) { return checkVersion(proc.text.trim()); } - proc = "git describe".execute(); + proc = "git describe".execute(null, projectDir); proc.waitFor(); if (proc.exitValue() == 0) { def describe = proc.text.trim() @@ -111,7 +111,7 @@ class SemverGitPlugin implements Plugin { if (project.ext.properties.containsKey("snapshotSuffix")) { snapshotSuffix = project.ext.snapshotSuffix } - project.version = getGitVersion(nextVersion, snapshotSuffix) + project.version = getGitVersion(nextVersion, snapshotSuffix, project.projectDir) project.task('showVersion') { group = 'Help' description = 'Show the project version'