Skip to content

Commit 2051ba7

Browse files
committed
determineCurrentVersion() in git repository needs to use iso-strict too
1 parent f3a9554 commit 2051ba7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/org/opensolaris/opengrok/history/GitRepository.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public class GitRepository extends Repository {
7878
private static final String ABBREV_LOG = "--abbrev=" + CSET_LEN;
7979
private static final String ABBREV_BLAME = "--abbrev=" + (CSET_LEN - 1);
8080

81+
/**
82+
* All git commands that emit date that needs to be parsed by
83+
* {@code getDateFormat()} should use this option.
84+
*/
85+
private static final String GIT_DATE_OPT = "--date=iso8601-strict";
86+
8187
/**
8288
* Pattern used to extract author/revision from git blame.
8389
*/
@@ -123,7 +129,7 @@ Executor getHistoryLogExecutor(final File file, String sinceRevision)
123129
cmd.add(ABBREV_LOG);
124130
cmd.add("--name-only");
125131
cmd.add("--pretty=fuller");
126-
cmd.add("--date=iso8601-strict");
132+
cmd.add(GIT_DATE_OPT);
127133

128134
if (file.isFile() && RuntimeEnvironment.getInstance().isHandleHistoryOfRenamedFiles()) {
129135
cmd.add("--follow");
@@ -708,16 +714,16 @@ String determineCurrentVersion() throws IOException {
708714
cmd.add(RepoCommand);
709715
cmd.add("log");
710716
cmd.add("-1");
711-
cmd.add("--pretty=%cd: %h %an %s");
712-
cmd.add("--date=rfc");
717+
cmd.add("--pretty=%cd# %h %an %s");
718+
cmd.add(GIT_DATE_OPT);
713719

714720
Executor executor = new Executor(cmd, directory);
715721
if (executor.exec(false) != 0) {
716722
throw new IOException(executor.getErrorString());
717723
}
718724

719725
String output = executor.getOutputString().trim();
720-
int indexOf = StringUtils.nthIndexOf(output, ":", 3);
726+
int indexOf = StringUtils.nthIndexOf(output, "#", 1);
721727
if (indexOf < 0) {
722728
throw new IOException(
723729
String.format("Couldn't extract date from \"%s\".",

test/org/opensolaris/opengrok/history/GitRepositoryTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ public void tearDown() {
7777
instance = null;
7878
}
7979

80+
@Test
81+
public void testDetermineCurrentVersion() throws Exception {
82+
File root = new File(repository.getSourceRoot(), "git");
83+
GitRepository gitrepo
84+
= (GitRepository) RepositoryFactory.getRepository(root);
85+
String ver = gitrepo.determineCurrentVersion();
86+
Assert.assertTrue(ver.startsWith("2017-01-26 14:51"));
87+
}
88+
8089
/**
8190
* Test of parseAnnotation method, of class GitRepository.
8291
* @throws java.lang.Exception

0 commit comments

Comments
 (0)