diff options
author | Thomas Wolf | 2019-07-17 15:49:07 +0000 |
---|---|---|
committer | Matthias Sohn | 2019-07-22 22:21:39 +0000 |
commit | 667dc0c5175637e32b4b9f41c37006e7f827beeb (patch) | |
tree | 682271fe39b60240ec2c65365a5bb7287752e8c4 /org.eclipse.egit.ui.test/src | |
parent | 374c142de4634d0888425368b138957c38498482 (diff) | |
download | egit-667dc0c5175637e32b4b9f41c37006e7f827beeb.tar.gz egit-667dc0c5175637e32b4b9f41c37006e7f827beeb.tar.xz egit-667dc0c5175637e32b4b9f41c37006e7f827beeb.zip |
Log an error if the reflog cannot be read
EGit reads the reflog in three places: in the SwitchToMenu, when
trying to get a short branch name, and in the reflog view. The
latter uses JGit's ReflogCommand and has its own fatal error handling.
In the other two places, a failure to read the reflog may cause severe
UI functionality loss. Therefore catch RuntimeExceptions, too, and
just log them.
In SwitchToMenu, also just log IOExceptions when the ref log cannot be
read. That way, there's a fair chance that the menu will still show
some branches.
Bug: 549235
Change-Id: I914536a65cec9d7e5c04199e989926d46e607427
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test/src')
-rw-r--r-- | org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java index 3c85947846..3c16f96923 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java @@ -13,10 +13,12 @@ package org.eclipse.egit.ui.internal.actions; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.File; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; @@ -105,7 +107,31 @@ public class SwitchToMenuTest extends LocalRepositoryTestCase { selectionWithProj1Common(); // delete reflog again to not confuse other tests - new File(gitDir, Constants.LOGS + "/" + Constants.HEAD).delete(); + assertTrue(new File(gitDir, Constants.LOGS + "/" + Constants.HEAD) + .delete()); + } + + @Test + public void selectionWithCorruptedReflog() throws Exception { + File gitDir = createProjectAndCommitToRepository(); + + // create additional reflog entries + try (Git git = new Git(lookupRepository(gitDir))) { + git.checkout().setName("stable").call(); + git.checkout().setName("master").call(); + } + + // Corrupt the reflog + File reflog = new File(gitDir, Constants.LOGS + "/" + Constants.HEAD); + List<String> lines = Files.readAllLines(reflog.toPath()); + assertTrue("Expected some lines in the reflog", lines.size() > 1); + lines.add(1, + "INTENTIONALLY CORRUPTED REFLOG. Just some text that definitely shouldn't be in a reflog."); + Files.write(reflog.toPath(), lines); + + selectionWithProj1Common(); + + assertTrue(reflog.delete()); } private void selectionWithProj1Common() { |