diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2024-04-29 00:11:46 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2024-04-29 15:05:32 +0200 |
commit | f1a9d25f40c30c8c0fc53cf1c811bde66abf11f0 (patch) | |
tree | e44d908b6fff95d01c0cb328f01d9716003d6d51 /org.eclipse.jgit.test | |
parent | 8a8e45dd27ff4b7cad0e2624e1b2bcce8b72ef72 (diff) | |
download | jgit-f1a9d25f40c30c8c0fc53cf1c811bde66abf11f0.tar.gz jgit-f1a9d25f40c30c8c0fc53cf1c811bde66abf11f0.zip |
[errorprone] Fix pattern see UnusedVariable
See https://errorprone.info/bugpattern/UnusedVariable
Change-Id: I75d7602af31ed7d3264d2beab2d159cfbf29e7cb
Diffstat (limited to 'org.eclipse.jgit.test')
8 files changed, 30 insertions, 36 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java index aa65985c55..3b0e184a42 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java @@ -13,6 +13,7 @@ package org.eclipse.jgit.api; import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.util.FileUtils.RECURSIVE; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; @@ -607,14 +608,14 @@ public class AddCommandTest extends RepositoryTestCase { try (Git git = new Git(db)) { DirCache dc = git.add().addFilepattern("a.txt").call(); - dc.getEntry(0).getObjectId(); + ObjectId oid = dc.getEntry(0).getObjectId(); try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) { writer.print("other content"); } dc = git.add().addFilepattern("a.txt").call(); - + assertNotEquals(oid, dc.getEntry(0).getObjectId()); assertEquals( "[a.txt, mode:100644, content:other content]", indexState(CONTENT)); @@ -632,7 +633,7 @@ public class AddCommandTest extends RepositoryTestCase { try (Git git = new Git(db)) { DirCache dc = git.add().addFilepattern("a.txt").call(); - dc.getEntry(0).getObjectId(); + ObjectId oid = dc.getEntry(0).getObjectId(); git.commit().setMessage("commit a.txt").call(); @@ -641,7 +642,7 @@ public class AddCommandTest extends RepositoryTestCase { } dc = git.add().addFilepattern("a.txt").call(); - + assertNotEquals(oid, dc.getEntry(0).getObjectId()); assertEquals( "[a.txt, mode:100644, content:other content]", indexState(CONTENT)); @@ -659,12 +660,12 @@ public class AddCommandTest extends RepositoryTestCase { try (Git git = new Git(db)) { DirCache dc = git.add().addFilepattern("a.txt").call(); - dc.getEntry(0).getObjectId(); + ObjectId oid = dc.getEntry(0).getObjectId(); FileUtils.delete(file); // is supposed to do nothing dc = git.add().addFilepattern("a.txt").call(); - + assertEquals(oid, dc.getEntry(0).getObjectId()); assertEquals( "[a.txt, mode:100644, content:content]", indexState(CONTENT)); @@ -684,12 +685,12 @@ public class AddCommandTest extends RepositoryTestCase { git.commit().setMessage("commit a.txt").call(); - dc.getEntry(0).getObjectId(); + ObjectId oid = dc.getEntry(0).getObjectId(); FileUtils.delete(file); // is supposed to do nothing dc = git.add().addFilepattern("a.txt").call(); - + assertEquals(oid, dc.getEntry(0).getObjectId()); assertEquals( "[a.txt, mode:100644, content:content]", indexState(CONTENT)); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java index b7abba4209..57e5d4958f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java @@ -284,11 +284,10 @@ public class CommitAndLogCommandTest extends RepositoryTestCase { // template) chars = commit.getFullMessage().getBytes(UTF_8); int lineStart = 0; - int lineEnd = 0; for (int i = 0; i < 4; i++) { lineStart = RawParseUtils.nextLF(chars, lineStart); } - lineEnd = RawParseUtils.nextLF(chars, lineStart); + int lineEnd = RawParseUtils.nextLF(chars, lineStart); String line = RawParseUtils.decode(chars, lineStart, lineEnd); @@ -303,13 +302,12 @@ public class CommitAndLogCommandTest extends RepositoryTestCase { // we should find the untouched template chars = commit.getFullMessage().getBytes(UTF_8); lineStart = 0; - lineEnd = 0; for (int i = 0; i < 4; i++) { lineStart = RawParseUtils.nextLF(chars, lineStart); } lineEnd = RawParseUtils.nextLF(chars, lineStart); - line = RawParseUtils.decode(chars, lineStart, lineEnd); + RawParseUtils.decode(chars, lineStart, lineEnd); assertTrue(commit.getFullMessage() .contains("Change-Id: I" + ObjectId.zeroId().getName())); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java index f52b715d39..cf952d2b77 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java @@ -172,9 +172,9 @@ public class PathCheckoutCommandTest extends RepositoryTestCase { @Test public void testUpdateWorkingDirectoryFromIndex() throws Exception { CheckoutCommand co = git.checkout(); - File written = writeTrashFile(FILE1, "3a"); + writeTrashFile(FILE1, "3a"); git.add().addFilepattern(FILE1).call(); - written = writeTrashFile(FILE1, ""); + File written = writeTrashFile(FILE1, ""); assertEquals("", read(written)); co.addPath(FILE1).call(); assertEquals("3a", read(written)); @@ -185,9 +185,9 @@ public class PathCheckoutCommandTest extends RepositoryTestCase { public void testUpdateWorkingDirectoryFromHeadWithIndexChange() throws Exception { CheckoutCommand co = git.checkout(); - File written = writeTrashFile(FILE1, "3a"); + writeTrashFile(FILE1, "3a"); git.add().addFilepattern(FILE1).call(); - written = writeTrashFile(FILE1, ""); + File written = writeTrashFile(FILE1, ""); assertEquals("", read(written)); co.addPath(FILE1).setStartPoint("HEAD").call(); assertEquals("3", read(written)); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java index f9af968a7e..c81731d746 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java @@ -69,8 +69,7 @@ public class StashDropCommandTest extends RepositoryTestCase { RevCommit stashed = git.stashCreate().call(); assertNotNull(stashed); stashRef = git.getRepository().exactRef(Constants.R_STASH); - assertEquals(stashed, - git.getRepository().exactRef(Constants.R_STASH).getObjectId()); + assertEquals(stashed, stashRef.getObjectId()); try { assertNull(git.stashDrop().setStashRef(100).call()); fail("Exception not thrown"); @@ -88,8 +87,7 @@ public class StashDropCommandTest extends RepositoryTestCase { RevCommit stashed = git.stashCreate().call(); assertNotNull(stashed); stashRef = git.getRepository().exactRef(Constants.R_STASH); - assertEquals(stashed, - git.getRepository().exactRef(Constants.R_STASH).getObjectId()); + assertEquals(stashed, stashRef.getObjectId()); assertNull(git.stashDrop().call()); stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNull(stashRef); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java index 5638c1f7d9..562a515721 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java @@ -104,10 +104,9 @@ public class CGitAttributesTest extends RepositoryTestCase { UTF_8))) { r.lines().forEach(line -> { // Parse the line and add to result map - int start = 0; int i = line.indexOf(':'); String path = line.substring(0, i).trim(); - start = i + 1; + int start = i + 1; i = line.indexOf(':', start); String key = line.substring(start, i).trim(); String value = line.substring(i + 1).trim(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java index 28d5ca726a..cb977bd601 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java @@ -513,7 +513,6 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { @Test public void testRefsCacheAfterUpdate() throws Exception { // Do not use the default repo for this case. - List<Ref> allRefs = db.getRefDatabase().getRefs(); ObjectId oldValue = db.resolve("HEAD"); ObjectId newValue = db.resolve("HEAD^"); // first make HEAD refer to loose ref @@ -529,7 +528,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { update = updateRef.update(); assertEquals(Result.FAST_FORWARD, update); - allRefs = db.getRefDatabase().getRefs(); + List<Ref> allRefs = db.getRefDatabase().getRefs(); Ref master = getRef(allRefs, "refs/heads/master").get(); Ref head = getRef(allRefs, "HEAD").get(); assertEquals("refs/heads/master", master.getName()); @@ -550,7 +549,6 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { @Test public void testRefsCacheAfterUpdateLooseOnly() throws Exception { // Do not use the default repo for this case. - List<Ref> allRefs = db.getRefDatabase().getRefs(); ObjectId oldValue = db.resolve("HEAD"); writeSymref(Constants.HEAD, "refs/heads/newref"); RefUpdate updateRef = db.updateRef(Constants.HEAD); @@ -559,7 +557,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { Result update = updateRef.update(); assertEquals(Result.NEW, update); - allRefs = db.getRefDatabase().getRefs(); + List<Ref> allRefs = db.getRefDatabase().getRefs(); Ref head = getRef(allRefs, "HEAD").get(); Ref newref = getRef(allRefs, "refs/heads/newref").get(); assertEquals("refs/heads/newref", newref.getName()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index 5c63c2df6b..31940a16f7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -1567,7 +1567,6 @@ public class ConfigTest { @Test public void testCommitTemplateEncoding() throws ConfigInvalidException, IOException { - Config config = new Config(null); File workTree = tmp.newFolder("dummy-worktree"); Repository repo = FileRepositoryBuilder .create(new File(workTree, ".git")); @@ -1576,7 +1575,7 @@ public class ConfigTest { String templateContent = "content of the template"; JGitTestUtil.write(tempFile, templateContent); String expectedTemplatePath = tempFile.getPath(); - config = parse("[i18n]\n\tcommitEncoding = utf-8\n" + Config config = parse("[i18n]\n\tcommitEncoding = utf-8\n" + "[commit]\n\ttemplate = " + Config.escapeValue(expectedTemplatePath) + "\n"); assertEquals(templateContent, @@ -1590,7 +1589,6 @@ public class ConfigTest { @Test(expected = ConfigInvalidException.class) public void testCommitTemplateWithInvalidEncoding() throws ConfigInvalidException, IOException { - Config config = new Config(null); File workTree = tmp.newFolder("dummy-worktree"); File tempFile = tmp.newFile("testCommitTemplate-"); Repository repo = FileRepositoryBuilder @@ -1598,7 +1596,7 @@ public class ConfigTest { repo.create(); String templateContent = "content of the template"; JGitTestUtil.write(tempFile, templateContent); - config = parse("[i18n]\n\tcommitEncoding = invalidEcoding\n" + Config config = parse("[i18n]\n\tcommitEncoding = invalidEcoding\n" + "[commit]\n\ttemplate = " + Config.escapeValue(tempFile.getPath()) + "\n"); config.get(CommitConfig.KEY).getCommitTemplateContent(repo); @@ -1607,7 +1605,6 @@ public class ConfigTest { @Test(expected = FileNotFoundException.class) public void testCommitTemplateWithInvalidPath() throws ConfigInvalidException, IOException { - Config config = new Config(null); File workTree = tmp.newFolder("dummy-worktree"); File tempFile = tmp.newFile("testCommitTemplate-"); Repository repo = FileRepositoryBuilder @@ -1617,7 +1614,8 @@ public class ConfigTest { JGitTestUtil.write(tempFile, templateContent); // commit message encoding String expectedTemplatePath = "~/nonExistingTemplate"; - config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); + Config config = parse( + "[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); String templatePath = config.get(CommitConfig.KEY) .getCommitTemplatePath(); assertEquals(expectedTemplatePath, templatePath); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java index 3f99fe2b26..3a036acaca 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java @@ -1446,6 +1446,8 @@ public class MergerTest extends RepositoryTestCase { git.checkout().setName("master").call(); mergeResult = git.merge().include(commitX).setStrategy(strategy) .call(); + assertEquals(MergeResult.MergeStatus.MERGED, + mergeResult.getMergeStatus()); // Now, merge commit A and B (i.e. "master" and "second-branch"). // None of them have the file "a", so there is no conflict, BUT while @@ -1739,25 +1741,25 @@ public class MergerTest extends RepositoryTestCase { git.add().addFilepattern("c").call(); RevCommit commitI = git.commit().setMessage("Initial commit").call(); - File a = writeTrashFile("a", "content in Ancestor"); + writeTrashFile("a", "content in Ancestor"); git.add().addFilepattern("a").call(); RevCommit commitA1 = git.commit().setMessage("Ancestor 1").call(); - a = writeTrashFile("a", "content in Child 1 (commited on master)"); + writeTrashFile("a", "content in Child 1 (commited on master)"); git.add().addFilepattern("a").call(); // commit C1M git.commit().setMessage("Child 1 on master").call(); git.checkout().setCreateBranch(true).setStartPoint(commitI).setName("branch-to-merge").call(); // "a" becomes executable in A2 - a = writeTrashFile("a", "content in Ancestor"); + File a = writeTrashFile("a", "content in Ancestor"); a.setExecutable(true); git.add().addFilepattern("a").call(); RevCommit commitA2 = git.commit().setMessage("Ancestor 2").call(); // second branch git.checkout().setCreateBranch(true).setStartPoint(commitA1).setName("second-branch").call(); - a = writeTrashFile("a", "content in Child 2 (commited on second-branch)"); + writeTrashFile("a", "content in Child 2 (commited on second-branch)"); git.add().addFilepattern("a").call(); // commit C2S git.commit().setMessage("Child 2 on second-branch").call(); |