diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java index f1a53d7dc..55f4d8b1b 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java @@ -63,7 +63,9 @@ public class BranchTest extends CLIRepositoryTestCase { @Before public void setUp() throws Exception { super.setUp(); - new Git(db).commit().setMessage("initial commit").call(); + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); + } } @Test @@ -95,13 +97,15 @@ public void testListDetached() throws Exception { @Test public void testListContains() throws Exception { - new Git(db).branchCreate().setName("initial").call(); - RevCommit second = new Git(db).commit().setMessage("second commit") - .call(); - assertEquals(toString(" initial", "* master"), - toString(execute("git branch --contains 6fd41be"))); - assertEquals("* master", - toString(execute("git branch --contains " + second.name()))); + try (Git git = new Git(db)) { + git.branchCreate().setName("initial").call(); + RevCommit second = git.commit().setMessage("second commit") + .call(); + assertEquals(toString(" initial", "* master"), + toString(execute("git branch --contains 6fd41be"))); + assertEquals("* master", + toString(execute("git branch --contains " + second.name()))); + } } @Test diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java index 6175b6c06..e690ad696 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java @@ -73,27 +73,33 @@ public class CheckoutTest extends CLIRepositoryTestCase { @Test public void testCheckoutSelf() throws Exception { - new Git(db).commit().setMessage("initial commit").call(); + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); - assertStringArrayEquals("Already on 'master'", - execute("git checkout master")); + assertStringArrayEquals("Already on 'master'", + execute("git checkout master")); + } } @Test public void testCheckoutBranch() throws Exception { - new Git(db).commit().setMessage("initial commit").call(); - new Git(db).branchCreate().setName("side").call(); + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); + git.branchCreate().setName("side").call(); - assertStringArrayEquals("Switched to branch 'side'", - execute("git checkout side")); + assertStringArrayEquals("Switched to branch 'side'", + execute("git checkout side")); + } } @Test public void testCheckoutNewBranch() throws Exception { - new Git(db).commit().setMessage("initial commit").call(); + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); - assertStringArrayEquals("Switched to a new branch 'side'", - execute("git checkout -b side")); + assertStringArrayEquals("Switched to a new branch 'side'", + execute("git checkout -b side")); + } } @Test @@ -105,11 +111,13 @@ public void testCheckoutNonExistingBranch() throws Exception { @Test public void testCheckoutNewBranchThatAlreadyExists() throws Exception { - new Git(db).commit().setMessage("initial commit").call(); + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); - assertStringArrayEquals( - "fatal: A branch named 'master' already exists.", + assertStringArrayEquals( + "fatal: A branch named 'master' already exists.", executeUnchecked("git checkout -b master")); + } } @Test @@ -127,32 +135,35 @@ public void testCheckoutUnresolvedHead() throws Exception { @Test public void testCheckoutHead() throws Exception { - new Git(db).commit().setMessage("initial commit").call(); + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); - assertStringArrayEquals("", execute("git checkout HEAD")); + assertStringArrayEquals("", execute("git checkout HEAD")); + } } @Test public void testCheckoutExistingBranchWithConflict() throws Exception { - Git git = new Git(db); - writeTrashFile("a", "Hello world a"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("commit file a").call(); - git.branchCreate().setName("branch_1").call(); - git.rm().addFilepattern("a").call(); - FileUtils.mkdirs(new File(db.getWorkTree(), "a")); - writeTrashFile("a/b", "Hello world b"); - git.add().addFilepattern("a/b").call(); - git.commit().setMessage("commit folder a").call(); - git.rm().addFilepattern("a").call(); - writeTrashFile("a", "New Hello world a"); - git.add().addFilepattern(".").call(); + try (Git git = new Git(db)) { + writeTrashFile("a", "Hello world a"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("commit file a").call(); + git.branchCreate().setName("branch_1").call(); + git.rm().addFilepattern("a").call(); + FileUtils.mkdirs(new File(db.getWorkTree(), "a")); + writeTrashFile("a/b", "Hello world b"); + git.add().addFilepattern("a/b").call(); + git.commit().setMessage("commit folder a").call(); + git.rm().addFilepattern("a").call(); + writeTrashFile("a", "New Hello world a"); + git.add().addFilepattern(".").call(); - String[] execute = execute("git checkout branch_1"); - assertEquals( - "error: Your local changes to the following files would be overwritten by checkout:", - execute[0]); - assertEquals("\ta", execute[1]); + String[] execute = execute("git checkout branch_1"); + assertEquals( + "error: Your local changes to the following files would be overwritten by checkout:", + execute[0]); + assertEquals("\ta", execute[1]); + } } /** @@ -174,41 +185,43 @@ public void testCheckoutExistingBranchWithConflict() throws Exception { */ @Test public void testCheckoutWithMissingWorkingTreeFile() throws Exception { - Git git = new Git(db); - File fileA = writeTrashFile("a", "Hello world a"); - writeTrashFile("b", "Hello world b"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("add files a & b").call(); - Ref branch_1 = git.branchCreate().setName("branch_1").call(); - writeTrashFile("a", "b"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("modify file a").call(); + try (Git git = new Git(db)) { + File fileA = writeTrashFile("a", "Hello world a"); + writeTrashFile("b", "Hello world b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add files a & b").call(); + Ref branch_1 = git.branchCreate().setName("branch_1").call(); + writeTrashFile("a", "b"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("modify file a").call(); - FileEntry entry = new FileTreeIterator.FileEntry(new File( - db.getWorkTree(), "a"), db.getFS()); - assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + FileEntry entry = new FileTreeIterator.FileEntry(new File( + db.getWorkTree(), "a"), db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); - FileUtils.delete(fileA); + FileUtils.delete(fileA); - git.checkout().setName(branch_1.getName()).call(); + git.checkout().setName(branch_1.getName()).call(); - entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), - db.getFS()); - assertEquals(FileMode.REGULAR_FILE, entry.getMode()); - assertEquals("Hello world a", read(fileA)); + entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), + db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + assertEquals("Hello world a", read(fileA)); + } } @Test public void testCheckoutOrphan() throws Exception { - Git git = new Git(db); - git.commit().setMessage("initial commit").call(); + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); - assertStringArrayEquals("Switched to a new branch 'new_branch'", - execute("git checkout --orphan new_branch")); - assertEquals("refs/heads/new_branch", - db.exactRef("HEAD").getTarget().getName()); - RevCommit commit = git.commit().setMessage("orphan commit").call(); - assertEquals(0, commit.getParentCount()); + assertStringArrayEquals("Switched to a new branch 'new_branch'", + execute("git checkout --orphan new_branch")); + assertEquals("refs/heads/new_branch", + db.exactRef("HEAD").getTarget().getName()); + RevCommit commit = git.commit().setMessage("orphan commit").call(); + assertEquals(0, commit.getParentCount()); + } } /** @@ -231,33 +244,34 @@ public void testCheckoutOrphan() throws Exception { @Test public void fileModeTestMissingThenFolderWithFileInWorkingTree() throws Exception { - Git git = new Git(db); - writeTrashFile("b", "Hello world b"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("add file b").call(); - Ref branch_1 = git.branchCreate().setName("branch_1").call(); - File folderA = new File(db.getWorkTree(), "a"); - FileUtils.mkdirs(folderA); - writeTrashFile("a/c", "Hello world c"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("add folder a").call(); + try (Git git = new Git(db)) { + writeTrashFile("b", "Hello world b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add file b").call(); + Ref branch_1 = git.branchCreate().setName("branch_1").call(); + File folderA = new File(db.getWorkTree(), "a"); + FileUtils.mkdirs(folderA); + writeTrashFile("a/c", "Hello world c"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add folder a").call(); - FileEntry entry = new FileTreeIterator.FileEntry(new File( - db.getWorkTree(), "a"), db.getFS()); - assertEquals(FileMode.TREE, entry.getMode()); + FileEntry entry = new FileTreeIterator.FileEntry(new File( + db.getWorkTree(), "a"), db.getFS()); + assertEquals(FileMode.TREE, entry.getMode()); - FileUtils.delete(folderA, FileUtils.RECURSIVE); - writeTrashFile("a", "b"); + FileUtils.delete(folderA, FileUtils.RECURSIVE); + writeTrashFile("a", "b"); - entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), - db.getFS()); - assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), + db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); - git.checkout().setName(branch_1.getName()).call(); + git.checkout().setName(branch_1.getName()).call(); - entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), - db.getFS()); - assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), + db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + } } /** @@ -279,30 +293,31 @@ public void fileModeTestMissingThenFolderWithFileInWorkingTree() */ @Test public void fileModeTestFolderWithMissingInWorkingTree() throws Exception { - Git git = new Git(db); - writeTrashFile("b", "Hello world b"); - writeTrashFile("a", "b"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("add file b & file a").call(); - Ref branch_1 = git.branchCreate().setName("branch_1").call(); - git.rm().addFilepattern("a").call(); - File folderA = new File(db.getWorkTree(), "a"); - FileUtils.mkdirs(folderA); - writeTrashFile("a/c", "Hello world c"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("add folder a").call(); + try (Git git = new Git(db)) { + writeTrashFile("b", "Hello world b"); + writeTrashFile("a", "b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add file b & file a").call(); + Ref branch_1 = git.branchCreate().setName("branch_1").call(); + git.rm().addFilepattern("a").call(); + File folderA = new File(db.getWorkTree(), "a"); + FileUtils.mkdirs(folderA); + writeTrashFile("a/c", "Hello world c"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add folder a").call(); - FileEntry entry = new FileTreeIterator.FileEntry(new File( - db.getWorkTree(), "a"), db.getFS()); - assertEquals(FileMode.TREE, entry.getMode()); + FileEntry entry = new FileTreeIterator.FileEntry(new File( + db.getWorkTree(), "a"), db.getFS()); + assertEquals(FileMode.TREE, entry.getMode()); - FileUtils.delete(folderA, FileUtils.RECURSIVE); + FileUtils.delete(folderA, FileUtils.RECURSIVE); - git.checkout().setName(branch_1.getName()).call(); + git.checkout().setName(branch_1.getName()).call(); - entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), - db.getFS()); - assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), + db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + } } /** @@ -324,32 +339,33 @@ public void fileModeTestFolderWithMissingInWorkingTree() throws Exception { */ @Test public void fileModeTestMissingWithFolderInWorkingTree() throws Exception { - Git git = new Git(db); - writeTrashFile("b", "Hello world b"); - writeTrashFile("a", "b"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("add file b & file a").call(); - Ref branch_1 = git.branchCreate().setName("branch_1").call(); - git.rm().addFilepattern("a").call(); - git.commit().setMessage("delete file a").call(); + try (Git git = new Git(db)) { + writeTrashFile("b", "Hello world b"); + writeTrashFile("a", "b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add file b & file a").call(); + Ref branch_1 = git.branchCreate().setName("branch_1").call(); + git.rm().addFilepattern("a").call(); + git.commit().setMessage("delete file a").call(); - FileUtils.mkdirs(new File(db.getWorkTree(), "a")); - writeTrashFile("a/c", "Hello world c"); + FileUtils.mkdirs(new File(db.getWorkTree(), "a")); + writeTrashFile("a/c", "Hello world c"); - FileEntry entry = new FileTreeIterator.FileEntry(new File( - db.getWorkTree(), "a"), db.getFS()); - assertEquals(FileMode.TREE, entry.getMode()); + FileEntry entry = new FileTreeIterator.FileEntry(new File( + db.getWorkTree(), "a"), db.getFS()); + assertEquals(FileMode.TREE, entry.getMode()); - CheckoutConflictException exception = null; - try { - git.checkout().setName(branch_1.getName()).call(); - } catch (CheckoutConflictException e) { - exception = e; + CheckoutConflictException exception = null; + try { + git.checkout().setName(branch_1.getName()).call(); + } catch (CheckoutConflictException e) { + exception = e; + } + assertNotNull(exception); + assertEquals(2, exception.getConflictingPaths().size()); + assertEquals("a", exception.getConflictingPaths().get(0)); + assertEquals("a/c", exception.getConflictingPaths().get(1)); } - assertNotNull(exception); - assertEquals(2, exception.getConflictingPaths().size()); - assertEquals("a", exception.getConflictingPaths().get(0)); - assertEquals("a/c", exception.getConflictingPaths().get(1)); } /** @@ -371,40 +387,41 @@ public void fileModeTestMissingWithFolderInWorkingTree() throws Exception { @Test public void fileModeTestFolderThenMissingWithFileInWorkingTree() throws Exception { - Git git = new Git(db); - FileUtils.mkdirs(new File(db.getWorkTree(), "a")); - writeTrashFile("a/c", "Hello world c"); - writeTrashFile("b", "Hello world b"); - git.add().addFilepattern(".").call(); - RevCommit commit1 = git.commit().setMessage("add folder a & file b") - .call(); - Ref branch_1 = git.branchCreate().setName("branch_1").call(); - git.rm().addFilepattern("a").call(); - RevCommit commit2 = git.commit().setMessage("delete folder a").call(); + try (Git git = new Git(db)) { + FileUtils.mkdirs(new File(db.getWorkTree(), "a")); + writeTrashFile("a/c", "Hello world c"); + writeTrashFile("b", "Hello world b"); + git.add().addFilepattern(".").call(); + RevCommit commit1 = git.commit().setMessage("add folder a & file b") + .call(); + Ref branch_1 = git.branchCreate().setName("branch_1").call(); + git.rm().addFilepattern("a").call(); + RevCommit commit2 = git.commit().setMessage("delete folder a").call(); - TreeWalk tw = new TreeWalk(db); - tw.addTree(commit1.getTree()); - tw.addTree(commit2.getTree()); - List scan = DiffEntry.scan(tw); - assertEquals(1, scan.size()); - assertEquals(FileMode.MISSING, scan.get(0).getNewMode()); - assertEquals(FileMode.TREE, scan.get(0).getOldMode()); + TreeWalk tw = new TreeWalk(db); + tw.addTree(commit1.getTree()); + tw.addTree(commit2.getTree()); + List scan = DiffEntry.scan(tw); + assertEquals(1, scan.size()); + assertEquals(FileMode.MISSING, scan.get(0).getNewMode()); + assertEquals(FileMode.TREE, scan.get(0).getOldMode()); - writeTrashFile("a", "b"); + writeTrashFile("a", "b"); - FileEntry entry = new FileTreeIterator.FileEntry(new File( - db.getWorkTree(), "a"), db.getFS()); - assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + FileEntry entry = new FileTreeIterator.FileEntry(new File( + db.getWorkTree(), "a"), db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); - CheckoutConflictException exception = null; - try { - git.checkout().setName(branch_1.getName()).call(); - } catch (CheckoutConflictException e) { - exception = e; + CheckoutConflictException exception = null; + try { + git.checkout().setName(branch_1.getName()).call(); + } catch (CheckoutConflictException e) { + exception = e; + } + assertNotNull(exception); + assertEquals(1, exception.getConflictingPaths().size()); + assertEquals("a", exception.getConflictingPaths().get(0)); } - assertNotNull(exception); - assertEquals(1, exception.getConflictingPaths().size()); - assertEquals("a", exception.getConflictingPaths().get(0)); } /** @@ -427,30 +444,31 @@ public void fileModeTestFolderThenMissingWithFileInWorkingTree() @Test public void fileModeTestFolderThenFileWithMissingInWorkingTree() throws Exception { - Git git = new Git(db); - FileUtils.mkdirs(new File(db.getWorkTree(), "a")); - writeTrashFile("a/c", "Hello world c"); - writeTrashFile("b", "Hello world b"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("add folder a & file b").call(); - Ref branch_1 = git.branchCreate().setName("branch_1").call(); - git.rm().addFilepattern("a").call(); - File fileA = new File(db.getWorkTree(), "a"); - writeTrashFile("a", "b"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("add file a").call(); + try (Git git = new Git(db)) { + FileUtils.mkdirs(new File(db.getWorkTree(), "a")); + writeTrashFile("a/c", "Hello world c"); + writeTrashFile("b", "Hello world b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add folder a & file b").call(); + Ref branch_1 = git.branchCreate().setName("branch_1").call(); + git.rm().addFilepattern("a").call(); + File fileA = new File(db.getWorkTree(), "a"); + writeTrashFile("a", "b"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("add file a").call(); - FileEntry entry = new FileTreeIterator.FileEntry(new File( - db.getWorkTree(), "a"), db.getFS()); - assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + FileEntry entry = new FileTreeIterator.FileEntry(new File( + db.getWorkTree(), "a"), db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); - FileUtils.delete(fileA); + FileUtils.delete(fileA); - git.checkout().setName(branch_1.getName()).call(); + git.checkout().setName(branch_1.getName()).call(); - entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), - db.getFS()); - assertEquals(FileMode.TREE, entry.getMode()); + entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), + db.getFS()); + assertEquals(FileMode.TREE, entry.getMode()); + } } /** @@ -471,38 +489,39 @@ public void fileModeTestFolderThenFileWithMissingInWorkingTree() */ @Test public void fileModeTestFileThenFileWithFolderInIndex() throws Exception { - Git git = new Git(db); - writeTrashFile("a", "Hello world a"); - writeTrashFile("b", "Hello world b"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("add files a & b").call(); - Ref branch_1 = git.branchCreate().setName("branch_1").call(); - writeTrashFile("a", "b"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("add file a").call(); + try (Git git = new Git(db)) { + writeTrashFile("a", "Hello world a"); + writeTrashFile("b", "Hello world b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add files a & b").call(); + Ref branch_1 = git.branchCreate().setName("branch_1").call(); + writeTrashFile("a", "b"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("add file a").call(); - FileEntry entry = new FileTreeIterator.FileEntry(new File( - db.getWorkTree(), "a"), db.getFS()); - assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + FileEntry entry = new FileTreeIterator.FileEntry(new File( + db.getWorkTree(), "a"), db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); - git.rm().addFilepattern("a").call(); - FileUtils.mkdirs(new File(db.getWorkTree(), "a")); - writeTrashFile("a/c", "Hello world c"); - git.add().addFilepattern(".").call(); + git.rm().addFilepattern("a").call(); + FileUtils.mkdirs(new File(db.getWorkTree(), "a")); + writeTrashFile("a/c", "Hello world c"); + git.add().addFilepattern(".").call(); - entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), - db.getFS()); - assertEquals(FileMode.TREE, entry.getMode()); + entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), + db.getFS()); + assertEquals(FileMode.TREE, entry.getMode()); - CheckoutConflictException exception = null; - try { - git.checkout().setName(branch_1.getName()).call(); - } catch (CheckoutConflictException e) { - exception = e; + CheckoutConflictException exception = null; + try { + git.checkout().setName(branch_1.getName()).call(); + } catch (CheckoutConflictException e) { + exception = e; + } + assertNotNull(exception); + assertEquals(1, exception.getConflictingPaths().size()); + assertEquals("a", exception.getConflictingPaths().get(0)); } - assertNotNull(exception); - assertEquals(1, exception.getConflictingPaths().size()); - assertEquals("a", exception.getConflictingPaths().get(0)); } /** @@ -524,66 +543,68 @@ public void fileModeTestFileThenFileWithFolderInIndex() throws Exception { */ @Test public void fileModeTestFileWithFolderInIndex() throws Exception { - Git git = new Git(db); - writeTrashFile("b", "Hello world b"); - writeTrashFile("a", "b"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("add file b & file a").call(); - Ref branch_1 = git.branchCreate().setName("branch_1").call(); - git.rm().addFilepattern("a").call(); - writeTrashFile("a", "Hello world a"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("add file a").call(); + try (Git git = new Git(db)) { + writeTrashFile("b", "Hello world b"); + writeTrashFile("a", "b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add file b & file a").call(); + Ref branch_1 = git.branchCreate().setName("branch_1").call(); + git.rm().addFilepattern("a").call(); + writeTrashFile("a", "Hello world a"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("add file a").call(); - FileEntry entry = new FileTreeIterator.FileEntry(new File( - db.getWorkTree(), "a"), db.getFS()); - assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + FileEntry entry = new FileTreeIterator.FileEntry(new File( + db.getWorkTree(), "a"), db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); - git.rm().addFilepattern("a").call(); - FileUtils.mkdirs(new File(db.getWorkTree(), "a")); - writeTrashFile("a/c", "Hello world c"); - git.add().addFilepattern(".").call(); + git.rm().addFilepattern("a").call(); + FileUtils.mkdirs(new File(db.getWorkTree(), "a")); + writeTrashFile("a/c", "Hello world c"); + git.add().addFilepattern(".").call(); - entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), - db.getFS()); - assertEquals(FileMode.TREE, entry.getMode()); + entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), + db.getFS()); + assertEquals(FileMode.TREE, entry.getMode()); - CheckoutConflictException exception = null; - try { - git.checkout().setName(branch_1.getName()).call(); - } catch (CheckoutConflictException e) { - exception = e; + CheckoutConflictException exception = null; + try { + git.checkout().setName(branch_1.getName()).call(); + } catch (CheckoutConflictException e) { + exception = e; + } + assertNotNull(exception); + assertEquals(1, exception.getConflictingPaths().size()); + assertEquals("a", exception.getConflictingPaths().get(0)); + + // TODO: ideally we'd like to get two paths from this exception + // assertEquals(2, exception.getConflictingPaths().size()); + // assertEquals("a", exception.getConflictingPaths().get(0)); + // assertEquals("a/c", exception.getConflictingPaths().get(1)); } - assertNotNull(exception); - assertEquals(1, exception.getConflictingPaths().size()); - assertEquals("a", exception.getConflictingPaths().get(0)); - - // TODO: ideally we'd like to get two paths from this exception - // assertEquals(2, exception.getConflictingPaths().size()); - // assertEquals("a", exception.getConflictingPaths().get(0)); - // assertEquals("a/c", exception.getConflictingPaths().get(1)); } @Test public void testCheckoutPath() throws Exception { - Git git = new Git(db); - writeTrashFile("a", "Hello world a"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("commit file a").call(); - git.branchCreate().setName("branch_1").call(); - git.checkout().setName("branch_1").call(); - File b = writeTrashFile("b", "Hello world b"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("commit file b").call(); - File a = writeTrashFile("a", "New Hello world a"); - git.add().addFilepattern(".").call(); - git.commit().setMessage("modified a").call(); - assertArrayEquals(new String[] { "" }, - execute("git checkout HEAD~2 -- a")); - assertEquals("Hello world a", read(a)); - assertArrayEquals(new String[] { "* branch_1", " master", "" }, - execute("git branch")); - assertEquals("Hello world b", read(b)); + try (Git git = new Git(db)) { + writeTrashFile("a", "Hello world a"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("commit file a").call(); + git.branchCreate().setName("branch_1").call(); + git.checkout().setName("branch_1").call(); + File b = writeTrashFile("b", "Hello world b"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("commit file b").call(); + File a = writeTrashFile("a", "New Hello world a"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("modified a").call(); + assertArrayEquals(new String[] { "" }, + execute("git checkout HEAD~2 -- a")); + assertEquals("Hello world a", read(a)); + assertArrayEquals(new String[] { "* branch_1", " master", "" }, + execute("git branch")); + assertEquals("Hello world b", read(b)); + } } @Test diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java index fde0a78bf..2cee2cb00 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java @@ -129,20 +129,20 @@ private static String longTypeOf(ObjectReader reader, final TrackingRefUpdate u) { final RefUpdate.Result r = u.getResult(); if (r == RefUpdate.Result.LOCK_FAILURE) - return "[lock fail]"; + return "[lock fail]"; //$NON-NLS-1$ if (r == RefUpdate.Result.IO_FAILURE) - return "[i/o error]"; + return "[i/o error]"; //$NON-NLS-1$ if (r == RefUpdate.Result.REJECTED) - return "[rejected]"; + return "[rejected]"; //$NON-NLS-1$ if (ObjectId.zeroId().equals(u.getNewObjectId())) - return "[deleted]"; + return "[deleted]"; //$NON-NLS-1$ if (r == RefUpdate.Result.NEW) { if (u.getRemoteName().startsWith(Constants.R_HEADS)) - return "[new branch]"; + return "[new branch]"; //$NON-NLS-1$ else if (u.getLocalName().startsWith(Constants.R_TAGS)) - return "[new tag]"; - return "[new]"; + return "[new tag]"; //$NON-NLS-1$ + return "[new]"; //$NON-NLS-1$ } if (r == RefUpdate.Result.FORCED) { @@ -158,7 +158,7 @@ else if (u.getLocalName().startsWith(Constants.R_TAGS)) } if (r == RefUpdate.Result.NO_CHANGE) - return "[up to date]"; + return "[up to date]"; //$NON-NLS-1$ return "[" + r.name() + "]"; //$NON-NLS-1$//$NON-NLS-2$ } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java index 8569e9278..faae13a4d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java @@ -74,7 +74,7 @@ protected void run() throws Exception { list(); else throw new NotSupportedException( - "only --list option is currently supported"); + "only --list option is currently supported"); //$NON-NLS-1$ } private void list() throws IOException, ConfigInvalidException { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java index d43424c7c..6947cdd10 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java @@ -324,7 +324,7 @@ private boolean showNotes(RevCommit c, NoteMap map, String label, return false; if (emptyLine) outw.println(); - outw.print("Notes"); + outw.print("Notes"); //$NON-NLS-1$ if (label != null) { outw.print(" ("); //$NON-NLS-1$ outw.print(label); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java index 9098c1263..33ea1deb8 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java @@ -182,15 +182,15 @@ private void printRefUpdateResult(final ObjectReader reader, switch (rru.getStatus()) { case OK: if (rru.isDelete()) - printUpdateLine('-', "[deleted]", null, remoteName, null); + printUpdateLine('-', "[deleted]", null, remoteName, null); //$NON-NLS-1$ else { final Ref oldRef = result.getAdvertisedRef(remoteName); if (oldRef == null) { final String summary; if (remoteName.startsWith(Constants.R_TAGS)) - summary = "[new tag]"; + summary = "[new tag]"; //$NON-NLS-1$ else - summary = "[new branch]"; + summary = "[new branch]"; //$NON-NLS-1$ printUpdateLine('*', summary, srcRef, remoteName, null); } else { boolean fastForward = rru.isFastForward(); @@ -206,16 +206,16 @@ private void printRefUpdateResult(final ObjectReader reader, break; case NON_EXISTING: - printUpdateLine('X', "[no match]", null, remoteName, null); + printUpdateLine('X', "[no match]", null, remoteName, null); //$NON-NLS-1$ break; case REJECTED_NODELETE: - printUpdateLine('!', "[rejected]", null, remoteName, + printUpdateLine('!', "[rejected]", null, remoteName, //$NON-NLS-1$ CLIText.get().remoteSideDoesNotSupportDeletingRefs); break; case REJECTED_NONFASTFORWARD: - printUpdateLine('!', "[rejected]", srcRef, remoteName, + printUpdateLine('!', "[rejected]", srcRef, remoteName, //$NON-NLS-1$ CLIText.get().nonFastForward); break; @@ -223,22 +223,22 @@ private void printRefUpdateResult(final ObjectReader reader, final String message = MessageFormat.format( CLIText.get().remoteRefObjectChangedIsNotExpectedOne, safeAbbreviate(reader, rru.getExpectedOldObjectId())); - printUpdateLine('!', "[rejected]", srcRef, remoteName, message); + printUpdateLine('!', "[rejected]", srcRef, remoteName, message); //$NON-NLS-1$ break; case REJECTED_OTHER_REASON: - printUpdateLine('!', "[remote rejected]", srcRef, remoteName, rru + printUpdateLine('!', "[remote rejected]", srcRef, remoteName, rru //$NON-NLS-1$ .getMessage()); break; case UP_TO_DATE: if (verbose) - printUpdateLine('=', "[up to date]", srcRef, remoteName, null); + printUpdateLine('=', "[up to date]", srcRef, remoteName, null); //$NON-NLS-1$ break; case NOT_ATTEMPTED: case AWAITING_REPORT: - printUpdateLine('?', "[unexpected push-process behavior]", srcRef, + printUpdateLine('?', "[unexpected push-process behavior]", srcRef, //$NON-NLS-1$ remoteName, rru.getMessage()); break; } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java index eb222747d..9cee37b79 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java @@ -89,7 +89,7 @@ protected void run() throws Exception { if (hard) mode = selectMode(mode, ResetType.HARD); if (mode == null) - throw die("no reset mode set"); + throw die("no reset mode set"); //$NON-NLS-1$ command.setMode(mode); } command.call(); @@ -98,7 +98,7 @@ protected void run() throws Exception { private static ResetType selectMode(ResetType mode, ResetType want) { if (mode != null) - throw die("reset modes are mutually exclusive, select one"); + throw die("reset modes are mutually exclusive, select one"); //$NON-NLS-1$ return want; } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java index 939f5836f..c5ecb8496 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java @@ -56,7 +56,8 @@ import org.kohsuke.args4j.Option; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.pgm.internal.CLIText;; +import org.eclipse.jgit.pgm.internal.CLIText; +import org.eclipse.jgit.pgm.opt.CmdLineParser; @Command(usage = "usage_RevParse") class RevParse extends TextBuiltin { @@ -84,7 +85,8 @@ protected void run() throws Exception { } } else { if (verify && commits.size() > 1) { - throw new CmdLineException(CLIText.get().needSingleRevision); + final CmdLineParser clp = new CmdLineParser(this); + throw new CmdLineException(clp, CLIText.get().needSingleRevision); } for (final ObjectId o : commits) { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java index d85698901..c96f2c1ba 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java @@ -136,7 +136,7 @@ protected boolean requiresRepository() { protected void run() throws Exception { mxBean = ManagementFactory.getThreadMXBean(); if (!mxBean.isCurrentThreadCpuTimeSupported()) - throw die("Current thread CPU time not supported on this JRE"); + throw die("Current thread CPU time not supported on this JRE"); //$NON-NLS-1$ if (gitDirs.isEmpty()) { RepositoryBuilder rb = new RepositoryBuilder() // @@ -248,18 +248,18 @@ public int compare(Test a, Test b) { File parent = directory.getParentFile(); if (name.equals(Constants.DOT_GIT) && parent != null) name = parent.getName(); - outw.println(name + ": start at " + startId.name()); + outw.println(name + ": start at " + startId.name()); //$NON-NLS-1$ } - outw.format(" %12d files, %8d commits\n", valueOf(files), + outw.format(" %12d files, %8d commits\n", valueOf(files), //$NON-NLS-1$ valueOf(commits)); - outw.format(" N=%10d min lines, %8d max lines\n", valueOf(minN), + outw.format(" N=%10d min lines, %8d max lines\n", valueOf(minN), //$NON-NLS-1$ valueOf(maxN)); - outw.format("%-25s %12s ( %12s %12s )\n", // - "Algorithm", "Time(ns)", "Time(ns) on", "Time(ns) on"); - outw.format("%-25s %12s ( %12s %12s )\n", // - "", "", "N=" + minN, "N=" + maxN); + outw.format("%-25s %12s ( %12s %12s )\n", //$NON-NLS-1$ + "Algorithm", "Time(ns)", "Time(ns) on", "Time(ns) on"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + outw.format("%-25s %12s ( %12s %12s )\n", //$NON-NLS-1$ + "", "", "N=" + minN, "N=" + maxN); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ outw.println("-----------------------------------------------------" //$NON-NLS-1$ + "----------------"); //$NON-NLS-1$ @@ -335,9 +335,9 @@ private List init() { } } } catch (IllegalArgumentException e) { - throw die("Cannot determine names", e); + throw die("Cannot determine names", e); //$NON-NLS-1$ } catch (IllegalAccessException e) { - throw die("Cannot determine names", e); + throw die("Cannot determine names", e); //$NON-NLS-1$ } return all; diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index 6260cd99f..e2f93f481 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java @@ -167,7 +167,7 @@ private void recreateCommitGraph() throws IOException { } } - pm.beginTask("Rewriting commits", queue.size()); + pm.beginTask("Rewriting commits", queue.size()); //$NON-NLS-1$ try (ObjectInserter oi = db.newObjectInserter()) { final ObjectId emptyTree = oi.insert(Constants.OBJ_TREE, new byte[] {}); @@ -203,7 +203,7 @@ private void recreateCommitGraph() throws IOException { newc.setAuthor(new PersonIdent(me, new Date(t.commitTime))); newc.setCommitter(newc.getAuthor()); newc.setParentIds(newParents); - newc.setMessage("ORIGINAL " + t.oldId.name() + "\n"); //$NON-NLS-2$ + newc.setMessage("ORIGINAL " + t.oldId.name() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ t.newId = oi.insert(newc); rewrites.put(t.oldId, t.newId); pm.update(1); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java index d3eb245cd..150fe6eec 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java @@ -87,9 +87,9 @@ protected void run() throws Exception { long size = reader.getObjectSize(obj, obj.getType()); try { if (BinaryDelta.getResultSize(delta) != size) - throw die("Object " + obj.name() + " is not a delta"); + throw die("Object " + obj.name() + " is not a delta"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (ArrayIndexOutOfBoundsException bad) { - throw die("Object " + obj.name() + " is not a delta"); + throw die("Object " + obj.name() + " is not a delta"); //$NON-NLS-1$ //$NON-NLS-2$ } outw.println(BinaryDelta.format(delta)); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java index 887ad08af..062f4e7a1 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java @@ -349,10 +349,10 @@ private void run(Repository db) throws Exception { name = parent.getName(); outw.println(name + ":"); //$NON-NLS-1$ } - outw.format(" %6d files; %5d avg. unique lines/file\n", // + outw.format(" %6d files; %5d avg. unique lines/file\n", //$NON-NLS-1$ valueOf(fileCnt), // valueOf(lineCnt / fileCnt)); - outw.format("%-20s %-15s %9s\n", "Hash", "Fold", "Max Len"); + outw.format("%-20s %-15s %9s\n", "Hash", "Fold", "Max Len"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ outw.println("-----------------------------------------------"); //$NON-NLS-1$ String lastHashName = null; for (Function fun : all) { @@ -405,9 +405,9 @@ private List init() { } } } catch (IllegalArgumentException e) { - throw new RuntimeException("Cannot determine names", e); + throw new RuntimeException("Cannot determine names", e); //$NON-NLS-1$ } catch (IllegalAccessException e) { - throw new RuntimeException("Cannot determine names", e); + throw new RuntimeException("Cannot determine names", e); //$NON-NLS-1$ } List all = new ArrayList(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java index 229fb67b0..6b8a61d4d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java @@ -109,7 +109,7 @@ public int parseArguments(final Parameters params) throws CmdLineException { try { dirc = DirCache.read(new File(name), FS.DETECTED); } catch (IOException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().notAnIndexFile, name), e); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notAnIndexFile, name), e); } setter.addValue(new DirCacheIterator(dirc)); return 1; @@ -119,20 +119,20 @@ public int parseArguments(final Parameters params) throws CmdLineException { try { id = clp.getRepository().resolve(name); } catch (IOException e) { - throw new CmdLineException(e.getMessage()); + throw new CmdLineException(clp, e.getMessage()); } if (id == null) - throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name)); final CanonicalTreeParser p = new CanonicalTreeParser(); try (ObjectReader curs = clp.getRepository().newObjectReader()) { p.reset(curs, clp.getRevWalk().parseTree(id)); } catch (MissingObjectException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name)); } catch (IncorrectObjectTypeException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name)); } catch (IOException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage())); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage())); } setter.addValue(p); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/ObjectIdHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/ObjectIdHandler.java index fa24d4b02..364809d83 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/ObjectIdHandler.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/ObjectIdHandler.java @@ -86,14 +86,14 @@ public int parseArguments(final Parameters params) throws CmdLineException { try { id = clp.getRepository().resolve(name); } catch (IOException e) { - throw new CmdLineException(e.getMessage()); + throw new CmdLineException(clp, e.getMessage()); } if (id != null) { setter.addValue(id); return 1; } - throw new CmdLineException(MessageFormat.format(CLIText.get().notAnObject, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notAnObject, name)); } @Override diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java index b1be128db..9ae56e4ea 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java @@ -96,8 +96,10 @@ public int parseArguments(final Parameters params) throws CmdLineException { final int dot2 = name.indexOf(".."); //$NON-NLS-1$ if (dot2 != -1) { if (!option.isMultiValued()) - throw new CmdLineException(MessageFormat.format(CLIText.get().onlyOneMetaVarExpectedIn - , option.metaVar(), name)); + throw new CmdLineException(clp, + MessageFormat.format( + CLIText.get().onlyOneMetaVarExpectedIn, + option.metaVar(), name)); final String left = name.substring(0, dot2); final String right = name.substring(dot2 + 2); @@ -116,20 +118,20 @@ private void addOne(final String name, final boolean interesting) try { id = clp.getRepository().resolve(name); } catch (IOException e) { - throw new CmdLineException(e.getMessage()); + throw new CmdLineException(clp, e.getMessage()); } if (id == null) - throw new CmdLineException(MessageFormat.format(CLIText.get().notACommit, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notACommit, name)); final RevCommit c; try { c = clp.getRevWalk().parseCommit(id); } catch (MissingObjectException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().notACommit, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notACommit, name)); } catch (IncorrectObjectTypeException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().notACommit, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notACommit, name)); } catch (IOException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage())); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage())); } if (interesting) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java index eb155af9f..e2879e076 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java @@ -89,20 +89,20 @@ public int parseArguments(final Parameters params) throws CmdLineException { try { id = clp.getRepository().resolve(name); } catch (IOException e) { - throw new CmdLineException(e.getMessage()); + throw new CmdLineException(clp, e.getMessage()); } if (id == null) - throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name)); final RevTree c; try { c = clp.getRevWalk().parseTree(id); } catch (MissingObjectException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name)); } catch (IncorrectObjectTypeException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name)); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notATree, name)); } catch (IOException e) { - throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage())); + throw new CmdLineException(clp, MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage())); } setter.addValue(c); return 1; diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/SubcommandHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/SubcommandHandler.java index c62ef0d2b..96f3ed0af 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/SubcommandHandler.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/SubcommandHandler.java @@ -63,6 +63,8 @@ * we can execute at runtime with the remaining arguments of the parser. */ public class SubcommandHandler extends OptionHandler { + private final org.eclipse.jgit.pgm.opt.CmdLineParser clp; + /** * Create a new handler for the command name. *

@@ -75,6 +77,7 @@ public class SubcommandHandler extends OptionHandler { public SubcommandHandler(final CmdLineParser parser, final OptionDef option, final Setter setter) { super(parser, option, setter); + clp = (org.eclipse.jgit.pgm.opt.CmdLineParser) parser; } @Override @@ -82,7 +85,7 @@ public int parseArguments(final Parameters params) throws CmdLineException { final String name = params.getParameter(0); final CommandRef cr = CommandCatalog.get(name); if (cr == null) - throw new CmdLineException(MessageFormat.format( + throw new CmdLineException(clp, MessageFormat.format( CLIText.get().notAJgitCommand, name)); // Force option parsing to stop. Everything after us should diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java index 910a645e2..2fe40b99e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java @@ -104,37 +104,38 @@ public void setUp() throws Exception { private Git setUpRepoWithRemote() throws Exception { Repository remoteRepository = createWorkRepository(); - Git remoteGit = new Git(remoteRepository); - // commit something - writeTrashFile("Test.txt", "Hello world"); - remoteGit.add().addFilepattern("Test.txt").call(); - initialCommit = remoteGit.commit().setMessage("Initial commit").call(); - writeTrashFile("Test.txt", "Some change"); - remoteGit.add().addFilepattern("Test.txt").call(); - secondCommit = remoteGit.commit().setMessage("Second commit").call(); - // create a master branch - RefUpdate rup = remoteRepository.updateRef("refs/heads/master"); - rup.setNewObjectId(initialCommit.getId()); - rup.forceUpdate(); + try (Git remoteGit = new Git(remoteRepository)) { + // commit something + writeTrashFile("Test.txt", "Hello world"); + remoteGit.add().addFilepattern("Test.txt").call(); + initialCommit = remoteGit.commit().setMessage("Initial commit").call(); + writeTrashFile("Test.txt", "Some change"); + remoteGit.add().addFilepattern("Test.txt").call(); + secondCommit = remoteGit.commit().setMessage("Second commit").call(); + // create a master branch + RefUpdate rup = remoteRepository.updateRef("refs/heads/master"); + rup.setNewObjectId(initialCommit.getId()); + rup.forceUpdate(); - Repository localRepository = createWorkRepository(); - Git localGit = new Git(localRepository); - StoredConfig config = localRepository.getConfig(); - RemoteConfig rc = new RemoteConfig(config, "origin"); - rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath())); - rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); - rc.update(config); - config.save(); - FetchResult res = localGit.fetch().setRemote("origin").call(); - assertFalse(res.getTrackingRefUpdates().isEmpty()); - rup = localRepository.updateRef("refs/heads/master"); - rup.setNewObjectId(initialCommit.getId()); - rup.forceUpdate(); - rup = localRepository.updateRef(Constants.HEAD); - rup.link("refs/heads/master"); - rup.setNewObjectId(initialCommit.getId()); - rup.update(); - return localGit; + Repository localRepository = createWorkRepository(); + Git localGit = new Git(localRepository); + StoredConfig config = localRepository.getConfig(); + RemoteConfig rc = new RemoteConfig(config, "origin"); + rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath())); + rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + rc.update(config); + config.save(); + FetchResult res = localGit.fetch().setRemote("origin").call(); + assertFalse(res.getTrackingRefUpdates().isEmpty()); + rup = localRepository.updateRef("refs/heads/master"); + rup.setNewObjectId(initialCommit.getId()); + rup.forceUpdate(); + rup = localRepository.updateRef(Constants.HEAD); + rup.link("refs/heads/master"); + rup.setNewObjectId(initialCommit.getId()); + rup.update(); + return localGit; + } } @Test @@ -192,8 +193,7 @@ public void testCreateAndList() throws Exception { @Test public void testListAllBranchesShouldNotDie() throws Exception { - Git git = setUpRepoWithRemote(); - git.branchList().setListMode(ListMode.ALL).call(); + setUpRepoWithRemote().branchList().setListMode(ListMode.ALL).call(); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index 4bfb128cb..362d7ac9c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -417,20 +417,20 @@ private Repository createRepositoryWithRemote() throws IOException, InvalidRemoteException, TransportException { // create second repository Repository db2 = createWorkRepository(); - Git git2 = new Git(db2); + try (Git git2 = new Git(db2)) { + // setup the second repository to fetch from the first repository + final StoredConfig config = db2.getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); + URIish uri = new URIish(db.getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.update(config); + config.save(); - // setup the second repository to fetch from the first repository - final StoredConfig config = db2.getConfig(); - RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); - URIish uri = new URIish(db.getDirectory().toURI().toURL()); - remoteConfig.addURI(uri); - remoteConfig.update(config); - config.save(); - - // fetch from first repository - RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*"); - git2.fetch().setRemote("origin").setRefSpecs(spec).call(); - return db2; + // fetch from first repository + RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*"); + git2.fetch().setRemote("origin").setRefSpecs(spec).call(); + return db2; + } } private CheckoutCommand newOrphanBranchCommand() { @@ -639,40 +639,41 @@ public void testSmudgeAndClean() throws IOException, GitAPIException { File clean_filter = writeTempFile("sed s/V1/@version/g -"); File smudge_filter = writeTempFile("sed s/@version/V1/g -"); - Git git = new Git(db); - StoredConfig config = git.getRepository().getConfig(); - config.setString("filter", "tstFilter", "smudge", - "sh " + slashify(smudge_filter.getPath())); - config.setString("filter", "tstFilter", "clean", - "sh " + slashify(clean_filter.getPath())); - config.save(); - writeTrashFile(".gitattributes", "*.txt filter=tstFilter"); - git.add().addFilepattern(".gitattributes").call(); - git.commit().setMessage("add attributes").call(); + try (Git git2 = new Git(db)) { + StoredConfig config = git.getRepository().getConfig(); + config.setString("filter", "tstFilter", "smudge", + "sh " + slashify(smudge_filter.getPath())); + config.setString("filter", "tstFilter", "clean", + "sh " + slashify(clean_filter.getPath())); + config.save(); + writeTrashFile(".gitattributes", "*.txt filter=tstFilter"); + git2.add().addFilepattern(".gitattributes").call(); + git2.commit().setMessage("add attributes").call(); - writeTrashFile("filterTest.txt", "hello world, V1"); - git.add().addFilepattern("filterTest.txt").call(); - git.commit().setMessage("add filterText.txt").call(); - assertEquals( - "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]", - indexState(CONTENT)); + writeTrashFile("filterTest.txt", "hello world, V1"); + git2.add().addFilepattern("filterTest.txt").call(); + git2.commit().setMessage("add filterText.txt").call(); + assertEquals( + "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]", + indexState(CONTENT)); - git.checkout().setCreateBranch(true).setName("test2").call(); - writeTrashFile("filterTest.txt", "bon giorno world, V1"); - git.add().addFilepattern("filterTest.txt").call(); - git.commit().setMessage("modified filterText.txt").call(); + git2.checkout().setCreateBranch(true).setName("test2").call(); + writeTrashFile("filterTest.txt", "bon giorno world, V1"); + git2.add().addFilepattern("filterTest.txt").call(); + git2.commit().setMessage("modified filterText.txt").call(); - assertTrue(git.status().call().isClean()); - assertEquals( - "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:bon giorno world, @version]", - indexState(CONTENT)); + assertTrue(git2.status().call().isClean()); + assertEquals( + "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:bon giorno world, @version]", + indexState(CONTENT)); - git.checkout().setName("refs/heads/test").call(); - assertTrue(git.status().call().isClean()); - assertEquals( - "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]", - indexState(CONTENT)); - assertEquals("hello world, V1", read("filterTest.txt")); + git2.checkout().setName("refs/heads/test").call(); + assertTrue(git2.status().call().isClean()); + assertEquals( + "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]", + indexState(CONTENT)); + assertEquals("hello world, V1", read("filterTest.txt")); + } } private File writeTempFile(String body) throws IOException { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java index dc7181aec..05fa00790 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java @@ -69,6 +69,7 @@ public void testIsValidPath() { assertFalse(isValidPath("a\u0000b")); } + @SuppressWarnings("unused") private static boolean isValidPath(String path) { try { new DirCacheEntry(path); @@ -78,6 +79,7 @@ private static boolean isValidPath(String path) { } } + @SuppressWarnings("unused") @Test public void testCreate_ByStringPath() { assertEquals("a", new DirCacheEntry("a").getPathString()); @@ -91,6 +93,7 @@ public void testCreate_ByStringPath() { } } + @SuppressWarnings("unused") @Test public void testCreate_ByStringPathAndStage() { DirCacheEntry e; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java index 6c8ee737d..dca356434 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java @@ -72,6 +72,7 @@ public void testShouldAutomagicallyDetectGitDirectory() throws Exception { .findGitDir(d).getGitDir()); } + @SuppressWarnings("unused") @Test public void emptyRepositoryFormatVersion() throws Exception { Repository r = createWorkRepository(); @@ -83,6 +84,7 @@ public void emptyRepositoryFormatVersion() throws Exception { new FileRepository(r.getDirectory()); } + @SuppressWarnings("unused") @Test public void invalidRepositoryFormatVersion() throws Exception { Repository r = createWorkRepository(); @@ -99,6 +101,7 @@ public void invalidRepositoryFormatVersion() throws Exception { } } + @SuppressWarnings("unused") @Test public void unknownRepositoryFormatVersion() throws Exception { Repository r = createWorkRepository(); 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 8744ed1bd..48434189e 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 @@ -558,13 +558,15 @@ public void testUpdateRefForwardWithCheck2() throws IOException { assertEquals(ppid, db.resolve("refs/heads/master")); // real test - RevCommit old = new RevWalk(db).parseCommit(ppid); - RefUpdate updateRef2 = db.updateRef("refs/heads/master"); - updateRef2.setExpectedOldObjectId(old); - updateRef2.setNewObjectId(pid); - Result update2 = updateRef2.update(); - assertEquals(Result.FAST_FORWARD, update2); - assertEquals(pid, db.resolve("refs/heads/master")); + try (RevWalk rw = new RevWalk(db)) { + RevCommit old = rw.parseCommit(ppid); + RefUpdate updateRef2 = db.updateRef("refs/heads/master"); + updateRef2.setExpectedOldObjectId(old); + updateRef2.setNewObjectId(pid); + Result update2 = updateRef2.update(); + assertEquals(Result.FAST_FORWARD, update2); + assertEquals(pid, db.resolve("refs/heads/master")); + } } /** @@ -707,9 +709,10 @@ public void testRenameBranchAlsoInPack() throws IOException { // Create new Repository instance, to reread caches and make sure our // assumptions are persistent. - Repository ndb = new FileRepository(db.getDirectory()); - assertEquals(rb2, ndb.resolve("refs/heads/new/name")); - assertNull(ndb.resolve("refs/heads/b")); + try (Repository ndb = new FileRepository(db.getDirectory())) { + assertEquals(rb2, ndb.resolve("refs/heads/new/name")); + assertNull(ndb.resolve("refs/heads/b")); + } } public void tryRenameWhenLocked(String toLock, String fromName, @@ -751,7 +754,7 @@ public void tryRenameWhenLocked(String toLock, String fromName, assertNull(db.resolve(toName)); assertEquals(oldFromLog.toString(), db.getReflogReader(fromName) .getReverseEntries().toString()); - if (oldHeadId != null) + if (oldHeadId != null && oldHeadLog != null) assertEquals(oldHeadLog.toString(), db.getReflogReader( Constants.HEAD).getReverseEntries().toString()); } finally { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java index a100ff357..f4d655f86 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java @@ -362,6 +362,7 @@ public void test007_Open() throws IOException { assertNotSame(db.getConfig(), db2.getConfig()); } + @SuppressWarnings("unused") @Test public void test008_FailOnWrongVersion() throws IOException { final File cfg = new File(db.getDirectory(), Constants.CONFIG); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java index 315c49560..1515a07ac 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java @@ -75,11 +75,13 @@ public void test002_NewIdent() { p.toExternalString()); } + @SuppressWarnings("unused") @Test(expected = IllegalArgumentException.class) public void nullForNameShouldThrowIllegalArgumentException() { new PersonIdent(null, "author@example.com"); } + @SuppressWarnings("unused") @Test(expected = IllegalArgumentException.class) public void nullForEmailShouldThrowIllegalArgumentException() { new PersonIdent("A U Thor", null); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java index e9ae1909e..3661677cd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java @@ -195,6 +195,7 @@ public void flush() throws IOException { assertEquals(1, flushCnt[0]); } + @SuppressWarnings("unused") @Test public void testConstructor_RejectsBadChannel() { try { @@ -220,6 +221,7 @@ public void testConstructor_RejectsBadChannel() { } } + @SuppressWarnings("unused") @Test public void testConstructor_RejectsBadBufferSize() { try { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java index 5e4ba3507..e55d37334 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java @@ -51,7 +51,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; @@ -64,24 +63,16 @@ public class URIishTest { private static final String GIT_SCHEME = "git://"; - @Test + @SuppressWarnings("unused") + @Test(expected = URISyntaxException.class) public void shouldRaiseErrorOnEmptyURI() throws Exception { - try { - new URIish(""); - fail("expecting an exception"); - } catch (URISyntaxException e) { - // expected - } + new URIish(""); } - @Test + @SuppressWarnings("unused") + @Test(expected = URISyntaxException.class) public void shouldRaiseErrorOnNullURI() throws Exception { - try { - new URIish((String) null); - fail("expecting an exception"); - } catch (URISyntaxException e) { - // expected - } + new URIish((String) null); } @Test @@ -634,34 +625,19 @@ public void testFileWithNoneUserHomeWithTilde() throws Exception { assertEquals(u, new URIish(str)); } - @Test + @Test(expected = IllegalArgumentException.class) public void testGetNullHumanishName() { - try { - new URIish().getHumanishName(); - fail("path must be not null"); - } catch (IllegalArgumentException e) { - // expected - } + new URIish().getHumanishName(); } - @Test + @Test(expected = IllegalArgumentException.class) public void testGetEmptyHumanishName() throws URISyntaxException { - try { - new URIish(GIT_SCHEME).getHumanishName(); - fail("empty path is useless"); - } catch (IllegalArgumentException e) { - // expected - } + new URIish(GIT_SCHEME).getHumanishName(); } - @Test + @Test(expected = IllegalArgumentException.class) public void testGetAbsEmptyHumanishName() { - try { - new URIish().getHumanishName(); - fail("empty path is useless"); - } catch (IllegalArgumentException e) { - // expected - } + new URIish().getHumanishName(); } @Test diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java index 5b7d84f73..4f9a5a317 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java @@ -179,7 +179,7 @@ public RevCommit call() throws GitAPIException, NoHeadException, processOptions(state, rw); - if (all && !repo.isBare() && repo.getWorkTree() != null) { + if (all && !repo.isBare()) { try (Git git = new Git(repo)) { git.add() .addFilepattern(".") //$NON-NLS-1$ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java index 5ce39c2e0..3ee2feb14 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java @@ -715,7 +715,7 @@ public String toPrivateASCIIString() { */ public String getHumanishName() throws IllegalArgumentException { String s = getPath(); - if ("/".equals(s) || "".equals(s)) //$NON-NLS-1$ + if ("/".equals(s) || "".equals(s)) //$NON-NLS-1$ //$NON-NLS-2$ s = getHost(); if (s == null) // $NON-NLS-1$ throw new IllegalArgumentException(); diff --git a/tools/version.sh b/tools/version.sh index a2f81290d..81ffe06b2 100755 --- a/tools/version.sh +++ b/tools/version.sh @@ -144,17 +144,6 @@ perl -pi~ -e ' } ' org.eclipse.jgit.packaging/org.*.feature/pom.xml -perl -pi~ -e ' - if ($ARGV ne $old_argv) { - $seen_version = 0; - $old_argv = $ARGV; - } - if ($seen_version < 5) { - $seen_version++ if - s{<(version)>.*}{<${1}>'"$POM_V"'}; - } - ' org.eclipse.jgit.packaging/org.eclipse.jgit.updatesite/pom.xml - perl -pi~ -e ' if ($ARGV ne $old_argv) { $seen_version = 0;