From 7620e8e734fcf7e317592004d4af10d8dfbebf99 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Wed, 2 Nov 2016 16:39:57 +0300 Subject: [PATCH] [git] do not loose commit which messages do not contain \n while reading details without changes --- .../src/git4idea/history/GitHistoryUtils.java | 2 +- .../git4idea/history/GitHistoryUtilsTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java index 39c24c130ec0..5109e61a09ae 100644 --- a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java +++ b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java @@ -593,7 +593,7 @@ public class GitHistoryUtils { output.setLength(0); } output.append(tail); - foundRecordEnd.set(false); + foundRecordEnd.set(tail.contains(GitLogParser.RECORD_END)); } } catch (Exception e) { diff --git a/plugins/git4idea/tests/git4idea/history/GitHistoryUtilsTest.java b/plugins/git4idea/tests/git4idea/history/GitHistoryUtilsTest.java index fe9b0c1835a5..98fe9905781f 100644 --- a/plugins/git4idea/tests/git4idea/history/GitHistoryUtilsTest.java +++ b/plugins/git4idea/tests/git4idea/history/GitHistoryUtilsTest.java @@ -406,6 +406,28 @@ public class GitHistoryUtilsTest extends GitSingleRepoTest { assertEquals(message, lastCommit.getFullMessage()); } + @Test + public void testLoadingDetailsWithoutChanges() throws Exception { + List expected = ContainerUtil.newArrayList(); + + String messageFile = "message.txt"; + touch(messageFile, ""); + + int commitCount = 100; + for (int i = 0; i < commitCount; i++) { + touch("file.txt", "content number " + i); + add(); + git("commit --allow-empty-message -F " + messageFile); + expected.add(last()); + } + expected = ContainerUtil.reverse(expected); + + List actualMessages = + GitHistoryUtils.loadDetails(myProject, myRepo.getRoot(), true, false, GitLogRecord::getHash, "--max-count=" + commitCount); + + assertEquals(expected, actualMessages); + } + private void assertHistory(@NotNull List actualRevisions) throws IOException, VcsException { assertEquals("Incorrect number of commits in history", myRevisions.size(), actualRevisions.size()); for (int i = 0; i < actualRevisions.size(); i++) {