From 49cee9cb36f7a5203794ea03a3c36fd3c5e88660 Mon Sep 17 00:00:00 2001 From: TheSnoozer Date: Sat, 2 Mar 2024 10:59:46 +0100 Subject: [PATCH] https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/701: add testcase to demonstrate the issue --- .../project13/core/AvailableGitTestRepo.java | 34 +++++++++++++++++++ .../GitCommitIdPluginIntegrationTest.java | 29 ++++++++++++++++ src/test/resources | 2 +- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/test/java/pl/project13/core/AvailableGitTestRepo.java b/src/test/java/pl/project13/core/AvailableGitTestRepo.java index 09f9931..83e7697 100644 --- a/src/test/java/pl/project13/core/AvailableGitTestRepo.java +++ b/src/test/java/pl/project13/core/AvailableGitTestRepo.java @@ -48,7 +48,41 @@ public enum AvailableGitTestRepo { */ WITH_COMMIT_THAT_HAS_TWO_TAGS("src/test/resources/_git_with_commit_that_has_two_tags"), ON_A_TAG_DIRTY("src/test/resources/_git_on_a_tag_dirty"), + /** + *
+   * * 01ed93c - (11 years ago) any commit, just a readme - Konrad Malawski (HEAD -> master)
+   * * 4ce26eb - (11 years ago) my submodules, yay - Konrad Malawski
+   * 
+ *
+   * $ git submodule status
+   * -9fd4b69a5ca09b60884d4f8f49ce16ea071077be module1
+   * -9fd4b69a5ca09b60884d4f8f49ce16ea071077be module2
+   * -9fd4b69a5ca09b60884d4f8f49ce16ea071077be module3
+   * -9fd4b69a5ca09b60884d4f8f49ce16ea071077be module4
+   *
+   * $ git config --file .gitmodules --get-regexp '\.url$'
+   * submodule.module1.url /tmp/module1
+   * submodule.module2.url /tmp/module1
+   * submodule.module3.url /tmp/module1
+   * submodule.module4.url /tmp/module1
+   * 
+ */ WITH_SUBMODULES("src/test/resources/_git_with_submodules"), + + /** + *
+   * 6455ccd - (3 minutes ago) init (HEAD -> master)
+   * 
+ *
+   * $ git submodule status
+   * 945bfe60e8a3eff168e915c7ba5bac37c9d0165b remote-module (heads/empty-branch)
+   *
+   * $ git submodule foreach --recursive git remote get-url origin
+   * Entering 'remote-module'
+   * git@github.com:git-commit-id/git-test-resources.git
+   * 
+ */ + WITH_REMOTE_SUBMODULES("src/test/resources/_git_with_remote_submodules"), /** *
    * b6a73ed - (HEAD, master) third addition (4 minutes ago) 

Konrad Malawski

diff --git a/src/test/java/pl/project13/core/GitCommitIdPluginIntegrationTest.java b/src/test/java/pl/project13/core/GitCommitIdPluginIntegrationTest.java index f39fcaf..e30e039 100644 --- a/src/test/java/pl/project13/core/GitCommitIdPluginIntegrationTest.java +++ b/src/test/java/pl/project13/core/GitCommitIdPluginIntegrationTest.java @@ -1583,6 +1583,35 @@ public void shouldGeneratePropertiesWithMultiplePrefixesAndReactorProject(boolea } } + @Test + @Parameters(method = "useNativeGit") + public void shouldWorkWithRelativeSubmodules(boolean useNativeGit) throws Exception { + // given + File parentProjectDotGit = + createTmpDotGitDirectory(AvailableGitTestRepo.WITH_REMOTE_SUBMODULES); + File submoduleDotGitDirectory = parentProjectDotGit.getParentFile().toPath().resolve( + "remote-module").resolve(".git").toFile(); + submoduleDotGitDirectory.getParentFile().mkdir(); + Files.write( + submoduleDotGitDirectory.toPath(), + "gitdir: ../.git/modules/remote-module".getBytes() + ); + + + GitCommitIdPlugin.Callback cb = + new GitCommitIdTestCallback() + .setDotGitDirectory(submoduleDotGitDirectory) + .setUseNativeGit(useNativeGit) + .build(); + Properties properties = new Properties(); + + // when + GitCommitIdPlugin.runPlugin(cb, properties); + + // then + assertPropertyPresentAndEqual(properties, "git.commit.id.abbrev", "945bfe6"); + } + @Test public void verifyAllowedCharactersForEvaluateOnCommit() { Pattern p = GitCommitIdPlugin.allowedCharactersForEvaluateOnCommit; diff --git a/src/test/resources b/src/test/resources index f2d84ee..0e54950 160000 --- a/src/test/resources +++ b/src/test/resources @@ -1 +1 @@ -Subproject commit f2d84eeaa87c2a28e482bbd64eae47402a08bff4 +Subproject commit 0e549504984403f5e9a29b9c104d027a705d9963