Skip to content

Commit 58f8ae2

Browse files
committed
Fix commit.committer.time provider
The "commit.committer.time" property has accidentally been using the "commit.author.time" provider since its inception. Fix this. References: #82
1 parent 4835217 commit 58f8ae2

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

src/main/java/pl/project13/core/GitDataProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ protected void loadGitData(@Nonnull String evaluateOnCommit, @Nonnull Map<String
286286
maybePut(properties, GitCommitPropertyConstant.COMMIT_ID_ABBREV, this::getAbbrevCommitId);
287287
// git.dirty
288288
maybePut(properties, GitCommitPropertyConstant.DIRTY, () -> Boolean.toString(isDirty()));
289-
// git.commit.author.name
289+
// git.commit.user.name
290290
maybePut(properties, GitCommitPropertyConstant.COMMIT_AUTHOR_NAME, this::getCommitAuthorName);
291-
// git.commit.author.email
291+
// git.commit.user.email
292292
maybePut(properties, GitCommitPropertyConstant.COMMIT_AUTHOR_EMAIL, this::getCommitAuthorEmail);
293293
// git.commit.message.full
294294
maybePut(properties, GitCommitPropertyConstant.COMMIT_MESSAGE_FULL, this::getCommitMessageFull);
@@ -299,7 +299,7 @@ protected void loadGitData(@Nonnull String evaluateOnCommit, @Nonnull Map<String
299299
// commit.author.time
300300
maybePut(properties, GitCommitPropertyConstant.COMMIT_AUTHOR_TIME, this::getCommitAuthorTime);
301301
// commit.committer.time
302-
maybePut(properties, GitCommitPropertyConstant.COMMIT_COMMITTER_TIME, this::getCommitAuthorTime);
302+
maybePut(properties, GitCommitPropertyConstant.COMMIT_COMMITTER_TIME, this::getCommitCommitterTime);
303303
// git remote.origin.url
304304
maybePut(properties, GitCommitPropertyConstant.REMOTE_ORIGIN_URL, this::getRemoteOriginUrl);
305305

src/test/java/pl/project13/core/AvailableGitTestRepo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public enum AvailableGitTestRepo {
6767
*/
6868
WITH_TAG_ON_DIFFERENT_BRANCH("src/test/resources/_git_with_tag_on_different_branch"),
6969
WITH_ONE_COMMIT_WITH_SPECIAL_CHARACTERS("src/test/resources/_git_one_commit_with_umlaut"),
70+
/**
71+
* <pre>
72+
* $ log --date=iso-strict --format='%h | cd=%cd | ad=%ad'
73+
* 7002d5c | cd=2014-09-19T17:23:04+02:00 | ad=2012-07-04T15:54:01+02:00
74+
* </pre>
75+
*/
76+
COMMITTER_DIFFERENT_FROM_AUTHOR("src/test/resources/_git_one_commit_with_umlaut"),
7077
/**
7178
* <pre>
7279
* b0c6d28b3b83bf7b905321bae67d9ca4c75a203f 2015-06-04 00:50:18 +0200 (HEAD, master)

src/test/java/pl/project13/core/GitCommitIdPluginIntegrationTest.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@
2626
import org.junit.runner.RunWith;
2727
import pl.project13.core.git.GitDescribeConfig;
2828
import pl.project13.core.util.GenericFileManager;
29-
import pl.project13.core.util.JsonManager;
30-
import pl.project13.core.util.XmlManager;
31-
import pl.project13.core.util.YmlManager;
3229

3330
import javax.annotation.Nonnull;
3431
import java.io.File;
3532
import java.io.IOException;
36-
import java.nio.charset.StandardCharsets;
3733
import java.nio.file.Files;
3834
import java.nio.file.Path;
3935
import java.text.SimpleDateFormat;
@@ -1061,6 +1057,45 @@ public void shouldGenerateClosestTagInformationWhenCommitHasTwoTags(boolean useN
10611057
assertPropertyPresentAndEqual(properties, "git.closest.tag.commit.count", "0");
10621058
}
10631059

1060+
@Test
1061+
@Parameters(method = "useNativeGit")
1062+
public void shouldGenerateCommitterAndAuthorInformation(boolean useNativeGit) throws Exception {
1063+
// given
1064+
File dotGitDirectory = createTmpDotGitDirectory(AvailableGitTestRepo.COMMITTER_DIFFERENT_FROM_AUTHOR);
1065+
1066+
GitCommitIdPlugin.Callback cb =
1067+
new GitCommitIdTestCallback()
1068+
.setDotGitDirectory(dotGitDirectory)
1069+
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX")
1070+
.setDateFormatTimeZone("UTC")
1071+
.setUseNativeGit(useNativeGit)
1072+
.build();
1073+
Properties properties = new Properties();
1074+
1075+
// when
1076+
GitCommitIdPlugin.runPlugin(cb, properties);
1077+
1078+
// then
1079+
assertThat(properties)
1080+
.containsKeys(
1081+
"git.commit.time",
1082+
"git.commit.committer.time",
1083+
"git.commit.author.time",
1084+
"git.commit.user.email",
1085+
"git.commit.user.name");
1086+
1087+
assertThat(properties.getProperty("git.commit.committer.time")).isNotEqualTo(properties.getProperty("git.commit.author.time"));
1088+
1089+
// Committer
1090+
assertPropertyPresentAndEqual(properties, "git.commit.committer.time", "2014-09-19T15:23:04Z");
1091+
assertThat(properties.getProperty("git.commit.committer.time")).isEqualTo(properties.getProperty("git.commit.time"));
1092+
1093+
// Author
1094+
assertPropertyPresentAndEqual(properties, "git.commit.author.time", "2012-07-04T13:54:01Z");
1095+
assertPropertyPresentAndEqual(properties, "git.commit.user.email", "john.doe@domain.com");
1096+
assertPropertyPresentAndEqual(properties, "git.commit.user.name", "John Doe");
1097+
}
1098+
10641099
@Test
10651100
@Parameters(method = "useNativeGit")
10661101
public void shouldUseDateFormatTimeZone(boolean useNativeGit) throws Exception {

0 commit comments

Comments
 (0)