diff --git a/README.md b/README.md index c15e29c..0793e81 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,8 @@ gitVersioning.apply { - `rev` Rev configuration will be used if no ref configuration is matching current git situation. - same as `branch(pattern)`/`tag(pattern)` configuration, except `pattern` parameter. + +- `gitDir` Provide git directory instead of default project directory, useful when applied from git submodule ### Format Placeholders diff --git a/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginConfig.java b/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginConfig.java index 0cc6ad7..6408b44 100644 --- a/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginConfig.java +++ b/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginConfig.java @@ -120,4 +120,6 @@ public void tag(String pattern, Action action) { this.list.add(ref); } } + + public String gitDir = null; } diff --git a/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java b/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java index 46751ed..2aba0b0 100644 --- a/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java +++ b/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java @@ -95,7 +95,14 @@ private void apply() throws IOException { } } - final GitSituation gitSituation = getGitSituation(project.getProjectDir()); + File gitDir; + if (config.gitDir != null) { + gitDir = new File(config.gitDir); + project.getLogger().lifecycle("git directory: " + gitDir); + } else { + gitDir = project.getProjectDir(); + } + final GitSituation gitSituation = getGitSituation(gitDir); if (gitSituation == null) { project.getLogger().warn("skip - project is not part of a git repository"); return;