Browse Source

Merge branch 'stable-4.2'

* stable-4.2:
  CheckoutCommandTest: Create Git instances in try-with-resource
  BranchCommandTest: Create Git instances in try-with-resource
  CheckoutTest: Create Git instances in try-with-resource
  BranchTest: Create Git instances in try-with-resource
  URIishTest: Use @Test annotation's `expected` argument
  Suppress "The allocated object is never used" warning in tests
  Add $NON-NLS to suppress "Non-externalized string literal" warnings
  Don't use deprecated constructors of CmdLineException
  Prepare 4.2.0-SNAPSHOT builds
  Remove org.eclipse.jgit.updatesite project from tools/version.sh
  RevParse: Remove superfluous semicolon
  RefUpdateTest: Use try-with-resource for auto-closable types
  RefUpdateTest: Add null check to prevent potential NPE
  CommitCommand: Remove redundant null check
  JGit v4.2.0.201512141825-rc1

Change-Id: I2179859289b2f2e3d0b7c6d02ef7e7890c467f7b
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.3
David Pursehouse 9 years ago
parent
commit
aca07fac46
  1. 20
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java
  2. 589
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java
  3. 16
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java
  4. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java
  5. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java
  6. 20
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java
  7. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java
  8. 6
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
  9. 20
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
  10. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
  11. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java
  12. 8
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
  13. 12
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java
  14. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/ObjectIdHandler.java
  15. 16
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java
  16. 10
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java
  17. 5
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/SubcommandHandler.java
  18. 66
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
  19. 97
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
  20. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
  21. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java
  22. 25
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
  23. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
  24. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java
  25. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
  26. 48
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
  27. 2
      org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
  28. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
  29. 11
      tools/version.sh

20
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java

@ -63,7 +63,9 @@ public class BranchTest extends CLIRepositoryTestCase {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
new Git(db).commit().setMessage("initial commit").call(); try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();
}
} }
@Test @Test
@ -95,13 +97,15 @@ public class BranchTest extends CLIRepositoryTestCase {
@Test @Test
public void testListContains() throws Exception { public void testListContains() throws Exception {
new Git(db).branchCreate().setName("initial").call(); try (Git git = new Git(db)) {
RevCommit second = new Git(db).commit().setMessage("second commit") git.branchCreate().setName("initial").call();
.call(); RevCommit second = git.commit().setMessage("second commit")
assertEquals(toString(" initial", "* master"), .call();
toString(execute("git branch --contains 6fd41be"))); assertEquals(toString(" initial", "* master"),
assertEquals("* master", toString(execute("git branch --contains 6fd41be")));
toString(execute("git branch --contains " + second.name()))); assertEquals("* master",
toString(execute("git branch --contains " + second.name())));
}
} }
@Test @Test

589
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java

@ -73,27 +73,33 @@ public class CheckoutTest extends CLIRepositoryTestCase {
@Test @Test
public void testCheckoutSelf() throws Exception { 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'", assertStringArrayEquals("Already on 'master'",
execute("git checkout master")); execute("git checkout master"));
}
} }
@Test @Test
public void testCheckoutBranch() throws Exception { public void testCheckoutBranch() throws Exception {
new Git(db).commit().setMessage("initial commit").call(); try (Git git = new Git(db)) {
new Git(db).branchCreate().setName("side").call(); git.commit().setMessage("initial commit").call();
git.branchCreate().setName("side").call();
assertStringArrayEquals("Switched to branch 'side'", assertStringArrayEquals("Switched to branch 'side'",
execute("git checkout side")); execute("git checkout side"));
}
} }
@Test @Test
public void testCheckoutNewBranch() throws Exception { 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'", assertStringArrayEquals("Switched to a new branch 'side'",
execute("git checkout -b side")); execute("git checkout -b side"));
}
} }
@Test @Test
@ -105,11 +111,13 @@ public class CheckoutTest extends CLIRepositoryTestCase {
@Test @Test
public void testCheckoutNewBranchThatAlreadyExists() throws Exception { 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( assertStringArrayEquals(
"fatal: A branch named 'master' already exists.", "fatal: A branch named 'master' already exists.",
executeUnchecked("git checkout -b master")); executeUnchecked("git checkout -b master"));
}
} }
@Test @Test
@ -127,32 +135,35 @@ public class CheckoutTest extends CLIRepositoryTestCase {
@Test @Test
public void testCheckoutHead() throws Exception { 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 @Test
public void testCheckoutExistingBranchWithConflict() throws Exception { public void testCheckoutExistingBranchWithConflict() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "Hello world a"); writeTrashFile("a", "Hello world a");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("commit file a").call(); git.commit().setMessage("commit file a").call();
git.branchCreate().setName("branch_1").call(); git.branchCreate().setName("branch_1").call();
git.rm().addFilepattern("a").call(); git.rm().addFilepattern("a").call();
FileUtils.mkdirs(new File(db.getWorkTree(), "a")); FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
writeTrashFile("a/b", "Hello world b"); writeTrashFile("a/b", "Hello world b");
git.add().addFilepattern("a/b").call(); git.add().addFilepattern("a/b").call();
git.commit().setMessage("commit folder a").call(); git.commit().setMessage("commit folder a").call();
git.rm().addFilepattern("a").call(); git.rm().addFilepattern("a").call();
writeTrashFile("a", "New Hello world a"); writeTrashFile("a", "New Hello world a");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
String[] execute = execute("git checkout branch_1"); String[] execute = execute("git checkout branch_1");
assertEquals( assertEquals(
"error: Your local changes to the following files would be overwritten by checkout:", "error: Your local changes to the following files would be overwritten by checkout:",
execute[0]); execute[0]);
assertEquals("\ta", execute[1]); assertEquals("\ta", execute[1]);
}
} }
/** /**
@ -174,41 +185,43 @@ public class CheckoutTest extends CLIRepositoryTestCase {
*/ */
@Test @Test
public void testCheckoutWithMissingWorkingTreeFile() throws Exception { public void testCheckoutWithMissingWorkingTreeFile() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "Hello world a"); File fileA = writeTrashFile("a", "Hello world a");
writeTrashFile("b", "Hello world b"); writeTrashFile("b", "Hello world b");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("add files a & b").call(); git.commit().setMessage("add files a & b").call();
Ref branch_1 = git.branchCreate().setName("branch_1").call(); Ref branch_1 = git.branchCreate().setName("branch_1").call();
writeTrashFile("a", "b"); writeTrashFile("a", "b");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
git.commit().setMessage("modify file a").call(); git.commit().setMessage("modify file a").call();
FileEntry entry = new FileTreeIterator.FileEntry(new File( FileEntry entry = new FileTreeIterator.FileEntry(new File(
db.getWorkTree(), "a"), db.getFS()); db.getWorkTree(), "a"), db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); 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"), entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
db.getFS()); db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); assertEquals(FileMode.REGULAR_FILE, entry.getMode());
assertEquals("Hello world a", read(fileA)); assertEquals("Hello world a", read(fileA));
}
} }
@Test @Test
public void testCheckoutOrphan() throws Exception { public void testCheckoutOrphan() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
assertStringArrayEquals("Switched to a new branch 'new_branch'", assertStringArrayEquals("Switched to a new branch 'new_branch'",
execute("git checkout --orphan new_branch")); execute("git checkout --orphan new_branch"));
assertEquals("refs/heads/new_branch", assertEquals("refs/heads/new_branch",
db.exactRef("HEAD").getTarget().getName()); db.exactRef("HEAD").getTarget().getName());
RevCommit commit = git.commit().setMessage("orphan commit").call(); RevCommit commit = git.commit().setMessage("orphan commit").call();
assertEquals(0, commit.getParentCount()); assertEquals(0, commit.getParentCount());
}
} }
/** /**
@ -231,33 +244,34 @@ public class CheckoutTest extends CLIRepositoryTestCase {
@Test @Test
public void fileModeTestMissingThenFolderWithFileInWorkingTree() public void fileModeTestMissingThenFolderWithFileInWorkingTree()
throws Exception { throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("b", "Hello world b"); writeTrashFile("b", "Hello world b");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("add file b").call(); git.commit().setMessage("add file b").call();
Ref branch_1 = git.branchCreate().setName("branch_1").call(); Ref branch_1 = git.branchCreate().setName("branch_1").call();
File folderA = new File(db.getWorkTree(), "a"); File folderA = new File(db.getWorkTree(), "a");
FileUtils.mkdirs(folderA); FileUtils.mkdirs(folderA);
writeTrashFile("a/c", "Hello world c"); writeTrashFile("a/c", "Hello world c");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("add folder a").call(); git.commit().setMessage("add folder a").call();
FileEntry entry = new FileTreeIterator.FileEntry(new File( FileEntry entry = new FileTreeIterator.FileEntry(new File(
db.getWorkTree(), "a"), db.getFS()); db.getWorkTree(), "a"), db.getFS());
assertEquals(FileMode.TREE, entry.getMode()); assertEquals(FileMode.TREE, entry.getMode());
FileUtils.delete(folderA, FileUtils.RECURSIVE); FileUtils.delete(folderA, FileUtils.RECURSIVE);
writeTrashFile("a", "b"); writeTrashFile("a", "b");
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
db.getFS()); db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); 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"), entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
db.getFS()); db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); assertEquals(FileMode.REGULAR_FILE, entry.getMode());
}
} }
/** /**
@ -279,30 +293,31 @@ public class CheckoutTest extends CLIRepositoryTestCase {
*/ */
@Test @Test
public void fileModeTestFolderWithMissingInWorkingTree() throws Exception { public void fileModeTestFolderWithMissingInWorkingTree() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("b", "Hello world b"); writeTrashFile("b", "Hello world b");
writeTrashFile("a", "b"); writeTrashFile("a", "b");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("add file b & file a").call(); git.commit().setMessage("add file b & file a").call();
Ref branch_1 = git.branchCreate().setName("branch_1").call(); Ref branch_1 = git.branchCreate().setName("branch_1").call();
git.rm().addFilepattern("a").call(); git.rm().addFilepattern("a").call();
File folderA = new File(db.getWorkTree(), "a"); File folderA = new File(db.getWorkTree(), "a");
FileUtils.mkdirs(folderA); FileUtils.mkdirs(folderA);
writeTrashFile("a/c", "Hello world c"); writeTrashFile("a/c", "Hello world c");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("add folder a").call(); git.commit().setMessage("add folder a").call();
FileEntry entry = new FileTreeIterator.FileEntry(new File( FileEntry entry = new FileTreeIterator.FileEntry(new File(
db.getWorkTree(), "a"), db.getFS()); db.getWorkTree(), "a"), db.getFS());
assertEquals(FileMode.TREE, entry.getMode()); 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"), entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
db.getFS()); db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); assertEquals(FileMode.REGULAR_FILE, entry.getMode());
}
} }
/** /**
@ -324,32 +339,33 @@ public class CheckoutTest extends CLIRepositoryTestCase {
*/ */
@Test @Test
public void fileModeTestMissingWithFolderInWorkingTree() throws Exception { public void fileModeTestMissingWithFolderInWorkingTree() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("b", "Hello world b"); writeTrashFile("b", "Hello world b");
writeTrashFile("a", "b"); writeTrashFile("a", "b");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("add file b & file a").call(); git.commit().setMessage("add file b & file a").call();
Ref branch_1 = git.branchCreate().setName("branch_1").call(); Ref branch_1 = git.branchCreate().setName("branch_1").call();
git.rm().addFilepattern("a").call(); git.rm().addFilepattern("a").call();
git.commit().setMessage("delete file a").call(); git.commit().setMessage("delete file a").call();
FileUtils.mkdirs(new File(db.getWorkTree(), "a")); FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
writeTrashFile("a/c", "Hello world c"); writeTrashFile("a/c", "Hello world c");
FileEntry entry = new FileTreeIterator.FileEntry(new File( FileEntry entry = new FileTreeIterator.FileEntry(new File(
db.getWorkTree(), "a"), db.getFS()); db.getWorkTree(), "a"), db.getFS());
assertEquals(FileMode.TREE, entry.getMode()); assertEquals(FileMode.TREE, entry.getMode());
CheckoutConflictException exception = null; CheckoutConflictException exception = null;
try { try {
git.checkout().setName(branch_1.getName()).call(); git.checkout().setName(branch_1.getName()).call();
} catch (CheckoutConflictException e) { } catch (CheckoutConflictException e) {
exception = 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 class CheckoutTest extends CLIRepositoryTestCase {
@Test @Test
public void fileModeTestFolderThenMissingWithFileInWorkingTree() public void fileModeTestFolderThenMissingWithFileInWorkingTree()
throws Exception { throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
FileUtils.mkdirs(new File(db.getWorkTree(), "a")); FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
writeTrashFile("a/c", "Hello world c"); writeTrashFile("a/c", "Hello world c");
writeTrashFile("b", "Hello world b"); writeTrashFile("b", "Hello world b");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
RevCommit commit1 = git.commit().setMessage("add folder a & file b") RevCommit commit1 = git.commit().setMessage("add folder a & file b")
.call(); .call();
Ref branch_1 = git.branchCreate().setName("branch_1").call(); Ref branch_1 = git.branchCreate().setName("branch_1").call();
git.rm().addFilepattern("a").call(); git.rm().addFilepattern("a").call();
RevCommit commit2 = git.commit().setMessage("delete folder a").call(); RevCommit commit2 = git.commit().setMessage("delete folder a").call();
TreeWalk tw = new TreeWalk(db); TreeWalk tw = new TreeWalk(db);
tw.addTree(commit1.getTree()); tw.addTree(commit1.getTree());
tw.addTree(commit2.getTree()); tw.addTree(commit2.getTree());
List<DiffEntry> scan = DiffEntry.scan(tw); List<DiffEntry> scan = DiffEntry.scan(tw);
assertEquals(1, scan.size()); assertEquals(1, scan.size());
assertEquals(FileMode.MISSING, scan.get(0).getNewMode()); assertEquals(FileMode.MISSING, scan.get(0).getNewMode());
assertEquals(FileMode.TREE, scan.get(0).getOldMode()); assertEquals(FileMode.TREE, scan.get(0).getOldMode());
writeTrashFile("a", "b"); writeTrashFile("a", "b");
FileEntry entry = new FileTreeIterator.FileEntry(new File( FileEntry entry = new FileTreeIterator.FileEntry(new File(
db.getWorkTree(), "a"), db.getFS()); db.getWorkTree(), "a"), db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); assertEquals(FileMode.REGULAR_FILE, entry.getMode());
CheckoutConflictException exception = null; CheckoutConflictException exception = null;
try { try {
git.checkout().setName(branch_1.getName()).call(); git.checkout().setName(branch_1.getName()).call();
} catch (CheckoutConflictException e) { } catch (CheckoutConflictException e) {
exception = 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 class CheckoutTest extends CLIRepositoryTestCase {
@Test @Test
public void fileModeTestFolderThenFileWithMissingInWorkingTree() public void fileModeTestFolderThenFileWithMissingInWorkingTree()
throws Exception { throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
FileUtils.mkdirs(new File(db.getWorkTree(), "a")); FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
writeTrashFile("a/c", "Hello world c"); writeTrashFile("a/c", "Hello world c");
writeTrashFile("b", "Hello world b"); writeTrashFile("b", "Hello world b");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("add folder a & file b").call(); git.commit().setMessage("add folder a & file b").call();
Ref branch_1 = git.branchCreate().setName("branch_1").call(); Ref branch_1 = git.branchCreate().setName("branch_1").call();
git.rm().addFilepattern("a").call(); git.rm().addFilepattern("a").call();
File fileA = new File(db.getWorkTree(), "a"); File fileA = new File(db.getWorkTree(), "a");
writeTrashFile("a", "b"); writeTrashFile("a", "b");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
git.commit().setMessage("add file a").call(); git.commit().setMessage("add file a").call();
FileEntry entry = new FileTreeIterator.FileEntry(new File( FileEntry entry = new FileTreeIterator.FileEntry(new File(
db.getWorkTree(), "a"), db.getFS()); db.getWorkTree(), "a"), db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); 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"), entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
db.getFS()); db.getFS());
assertEquals(FileMode.TREE, entry.getMode()); assertEquals(FileMode.TREE, entry.getMode());
}
} }
/** /**
@ -471,38 +489,39 @@ public class CheckoutTest extends CLIRepositoryTestCase {
*/ */
@Test @Test
public void fileModeTestFileThenFileWithFolderInIndex() throws Exception { public void fileModeTestFileThenFileWithFolderInIndex() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "Hello world a"); writeTrashFile("a", "Hello world a");
writeTrashFile("b", "Hello world b"); writeTrashFile("b", "Hello world b");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("add files a & b").call(); git.commit().setMessage("add files a & b").call();
Ref branch_1 = git.branchCreate().setName("branch_1").call(); Ref branch_1 = git.branchCreate().setName("branch_1").call();
writeTrashFile("a", "b"); writeTrashFile("a", "b");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
git.commit().setMessage("add file a").call(); git.commit().setMessage("add file a").call();
FileEntry entry = new FileTreeIterator.FileEntry(new File( FileEntry entry = new FileTreeIterator.FileEntry(new File(
db.getWorkTree(), "a"), db.getFS()); db.getWorkTree(), "a"), db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); assertEquals(FileMode.REGULAR_FILE, entry.getMode());
git.rm().addFilepattern("a").call(); git.rm().addFilepattern("a").call();
FileUtils.mkdirs(new File(db.getWorkTree(), "a")); FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
writeTrashFile("a/c", "Hello world c"); writeTrashFile("a/c", "Hello world c");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
db.getFS()); db.getFS());
assertEquals(FileMode.TREE, entry.getMode()); assertEquals(FileMode.TREE, entry.getMode());
CheckoutConflictException exception = null; CheckoutConflictException exception = null;
try { try {
git.checkout().setName(branch_1.getName()).call(); git.checkout().setName(branch_1.getName()).call();
} catch (CheckoutConflictException e) { } catch (CheckoutConflictException e) {
exception = 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 class CheckoutTest extends CLIRepositoryTestCase {
*/ */
@Test @Test
public void fileModeTestFileWithFolderInIndex() throws Exception { public void fileModeTestFileWithFolderInIndex() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("b", "Hello world b"); writeTrashFile("b", "Hello world b");
writeTrashFile("a", "b"); writeTrashFile("a", "b");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("add file b & file a").call(); git.commit().setMessage("add file b & file a").call();
Ref branch_1 = git.branchCreate().setName("branch_1").call(); Ref branch_1 = git.branchCreate().setName("branch_1").call();
git.rm().addFilepattern("a").call(); git.rm().addFilepattern("a").call();
writeTrashFile("a", "Hello world a"); writeTrashFile("a", "Hello world a");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
git.commit().setMessage("add file a").call(); git.commit().setMessage("add file a").call();
FileEntry entry = new FileTreeIterator.FileEntry(new File( FileEntry entry = new FileTreeIterator.FileEntry(new File(
db.getWorkTree(), "a"), db.getFS()); db.getWorkTree(), "a"), db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); assertEquals(FileMode.REGULAR_FILE, entry.getMode());
git.rm().addFilepattern("a").call(); git.rm().addFilepattern("a").call();
FileUtils.mkdirs(new File(db.getWorkTree(), "a")); FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
writeTrashFile("a/c", "Hello world c"); writeTrashFile("a/c", "Hello world c");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
db.getFS()); db.getFS());
assertEquals(FileMode.TREE, entry.getMode()); assertEquals(FileMode.TREE, entry.getMode());
CheckoutConflictException exception = null; CheckoutConflictException exception = null;
try { try {
git.checkout().setName(branch_1.getName()).call(); git.checkout().setName(branch_1.getName()).call();
} catch (CheckoutConflictException e) { } catch (CheckoutConflictException e) {
exception = 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 @Test
public void testCheckoutPath() throws Exception { public void testCheckoutPath() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "Hello world a"); writeTrashFile("a", "Hello world a");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("commit file a").call(); git.commit().setMessage("commit file a").call();
git.branchCreate().setName("branch_1").call(); git.branchCreate().setName("branch_1").call();
git.checkout().setName("branch_1").call(); git.checkout().setName("branch_1").call();
File b = writeTrashFile("b", "Hello world b"); File b = writeTrashFile("b", "Hello world b");
git.add().addFilepattern("b").call(); git.add().addFilepattern("b").call();
git.commit().setMessage("commit file b").call(); git.commit().setMessage("commit file b").call();
File a = writeTrashFile("a", "New Hello world a"); File a = writeTrashFile("a", "New Hello world a");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("modified a").call(); git.commit().setMessage("modified a").call();
assertArrayEquals(new String[] { "" }, assertArrayEquals(new String[] { "" },
execute("git checkout HEAD~2 -- a")); execute("git checkout HEAD~2 -- a"));
assertEquals("Hello world a", read(a)); assertEquals("Hello world a", read(a));
assertArrayEquals(new String[] { "* branch_1", " master", "" }, assertArrayEquals(new String[] { "* branch_1", " master", "" },
execute("git branch")); execute("git branch"));
assertEquals("Hello world b", read(b)); assertEquals("Hello world b", read(b));
}
} }
@Test @Test

16
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java

@ -129,20 +129,20 @@ abstract class AbstractFetchCommand extends TextBuiltin {
final TrackingRefUpdate u) { final TrackingRefUpdate u) {
final RefUpdate.Result r = u.getResult(); final RefUpdate.Result r = u.getResult();
if (r == RefUpdate.Result.LOCK_FAILURE) if (r == RefUpdate.Result.LOCK_FAILURE)
return "[lock fail]"; return "[lock fail]"; //$NON-NLS-1$
if (r == RefUpdate.Result.IO_FAILURE) if (r == RefUpdate.Result.IO_FAILURE)
return "[i/o error]"; return "[i/o error]"; //$NON-NLS-1$
if (r == RefUpdate.Result.REJECTED) if (r == RefUpdate.Result.REJECTED)
return "[rejected]"; return "[rejected]"; //$NON-NLS-1$
if (ObjectId.zeroId().equals(u.getNewObjectId())) if (ObjectId.zeroId().equals(u.getNewObjectId()))
return "[deleted]"; return "[deleted]"; //$NON-NLS-1$
if (r == RefUpdate.Result.NEW) { if (r == RefUpdate.Result.NEW) {
if (u.getRemoteName().startsWith(Constants.R_HEADS)) if (u.getRemoteName().startsWith(Constants.R_HEADS))
return "[new branch]"; return "[new branch]"; //$NON-NLS-1$
else if (u.getLocalName().startsWith(Constants.R_TAGS)) else if (u.getLocalName().startsWith(Constants.R_TAGS))
return "[new tag]"; return "[new tag]"; //$NON-NLS-1$
return "[new]"; return "[new]"; //$NON-NLS-1$
} }
if (r == RefUpdate.Result.FORCED) { if (r == RefUpdate.Result.FORCED) {
@ -158,7 +158,7 @@ abstract class AbstractFetchCommand extends TextBuiltin {
} }
if (r == RefUpdate.Result.NO_CHANGE) 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$ return "[" + r.name() + "]"; //$NON-NLS-1$//$NON-NLS-2$
} }

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java

@ -74,7 +74,7 @@ class Config extends TextBuiltin {
list(); list();
else else
throw new NotSupportedException( throw new NotSupportedException(
"only --list option is currently supported"); "only --list option is currently supported"); //$NON-NLS-1$
} }
private void list() throws IOException, ConfigInvalidException { private void list() throws IOException, ConfigInvalidException {

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java

@ -324,7 +324,7 @@ class Log extends RevWalkTextBuiltin {
return false; return false;
if (emptyLine) if (emptyLine)
outw.println(); outw.println();
outw.print("Notes"); outw.print("Notes"); //$NON-NLS-1$
if (label != null) { if (label != null) {
outw.print(" ("); //$NON-NLS-1$ outw.print(" ("); //$NON-NLS-1$
outw.print(label); outw.print(label);

20
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java

@ -182,15 +182,15 @@ class Push extends TextBuiltin {
switch (rru.getStatus()) { switch (rru.getStatus()) {
case OK: case OK:
if (rru.isDelete()) if (rru.isDelete())
printUpdateLine('-', "[deleted]", null, remoteName, null); printUpdateLine('-', "[deleted]", null, remoteName, null); //$NON-NLS-1$
else { else {
final Ref oldRef = result.getAdvertisedRef(remoteName); final Ref oldRef = result.getAdvertisedRef(remoteName);
if (oldRef == null) { if (oldRef == null) {
final String summary; final String summary;
if (remoteName.startsWith(Constants.R_TAGS)) if (remoteName.startsWith(Constants.R_TAGS))
summary = "[new tag]"; summary = "[new tag]"; //$NON-NLS-1$
else else
summary = "[new branch]"; summary = "[new branch]"; //$NON-NLS-1$
printUpdateLine('*', summary, srcRef, remoteName, null); printUpdateLine('*', summary, srcRef, remoteName, null);
} else { } else {
boolean fastForward = rru.isFastForward(); boolean fastForward = rru.isFastForward();
@ -206,16 +206,16 @@ class Push extends TextBuiltin {
break; break;
case NON_EXISTING: case NON_EXISTING:
printUpdateLine('X', "[no match]", null, remoteName, null); printUpdateLine('X', "[no match]", null, remoteName, null); //$NON-NLS-1$
break; break;
case REJECTED_NODELETE: case REJECTED_NODELETE:
printUpdateLine('!', "[rejected]", null, remoteName, printUpdateLine('!', "[rejected]", null, remoteName, //$NON-NLS-1$
CLIText.get().remoteSideDoesNotSupportDeletingRefs); CLIText.get().remoteSideDoesNotSupportDeletingRefs);
break; break;
case REJECTED_NONFASTFORWARD: case REJECTED_NONFASTFORWARD:
printUpdateLine('!', "[rejected]", srcRef, remoteName, printUpdateLine('!', "[rejected]", srcRef, remoteName, //$NON-NLS-1$
CLIText.get().nonFastForward); CLIText.get().nonFastForward);
break; break;
@ -223,22 +223,22 @@ class Push extends TextBuiltin {
final String message = MessageFormat.format( final String message = MessageFormat.format(
CLIText.get().remoteRefObjectChangedIsNotExpectedOne, CLIText.get().remoteRefObjectChangedIsNotExpectedOne,
safeAbbreviate(reader, rru.getExpectedOldObjectId())); safeAbbreviate(reader, rru.getExpectedOldObjectId()));
printUpdateLine('!', "[rejected]", srcRef, remoteName, message); printUpdateLine('!', "[rejected]", srcRef, remoteName, message); //$NON-NLS-1$
break; break;
case REJECTED_OTHER_REASON: case REJECTED_OTHER_REASON:
printUpdateLine('!', "[remote rejected]", srcRef, remoteName, rru printUpdateLine('!', "[remote rejected]", srcRef, remoteName, rru //$NON-NLS-1$
.getMessage()); .getMessage());
break; break;
case UP_TO_DATE: case UP_TO_DATE:
if (verbose) if (verbose)
printUpdateLine('=', "[up to date]", srcRef, remoteName, null); printUpdateLine('=', "[up to date]", srcRef, remoteName, null); //$NON-NLS-1$
break; break;
case NOT_ATTEMPTED: case NOT_ATTEMPTED:
case AWAITING_REPORT: case AWAITING_REPORT:
printUpdateLine('?', "[unexpected push-process behavior]", srcRef, printUpdateLine('?', "[unexpected push-process behavior]", srcRef, //$NON-NLS-1$
remoteName, rru.getMessage()); remoteName, rru.getMessage());
break; break;
} }

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java

@ -89,7 +89,7 @@ class Reset extends TextBuiltin {
if (hard) if (hard)
mode = selectMode(mode, ResetType.HARD); mode = selectMode(mode, ResetType.HARD);
if (mode == null) if (mode == null)
throw die("no reset mode set"); throw die("no reset mode set"); //$NON-NLS-1$
command.setMode(mode); command.setMode(mode);
} }
command.call(); command.call();
@ -98,7 +98,7 @@ class Reset extends TextBuiltin {
private static ResetType selectMode(ResetType mode, ResetType want) { private static ResetType selectMode(ResetType mode, ResetType want) {
if (mode != null) 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; return want;
} }
} }

6
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java

@ -56,7 +56,8 @@ import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.Option; import org.kohsuke.args4j.Option;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref; 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") @Command(usage = "usage_RevParse")
class RevParse extends TextBuiltin { class RevParse extends TextBuiltin {
@ -84,7 +85,8 @@ class RevParse extends TextBuiltin {
} }
} else { } else {
if (verify && commits.size() > 1) { 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) { for (final ObjectId o : commits) {

20
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java

@ -136,7 +136,7 @@ class DiffAlgorithms extends TextBuiltin {
protected void run() throws Exception { protected void run() throws Exception {
mxBean = ManagementFactory.getThreadMXBean(); mxBean = ManagementFactory.getThreadMXBean();
if (!mxBean.isCurrentThreadCpuTimeSupported()) 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()) { if (gitDirs.isEmpty()) {
RepositoryBuilder rb = new RepositoryBuilder() // RepositoryBuilder rb = new RepositoryBuilder() //
@ -248,18 +248,18 @@ class DiffAlgorithms extends TextBuiltin {
File parent = directory.getParentFile(); File parent = directory.getParentFile();
if (name.equals(Constants.DOT_GIT) && parent != null) if (name.equals(Constants.DOT_GIT) && parent != null)
name = parent.getName(); 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)); 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)); valueOf(maxN));
outw.format("%-25s %12s ( %12s %12s )\n", // outw.format("%-25s %12s ( %12s %12s )\n", //$NON-NLS-1$
"Algorithm", "Time(ns)", "Time(ns) on", "Time(ns) on"); "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", // outw.format("%-25s %12s ( %12s %12s )\n", //$NON-NLS-1$
"", "", "N=" + minN, "N=" + maxN); "", "", "N=" + minN, "N=" + maxN); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
outw.println("-----------------------------------------------------" //$NON-NLS-1$ outw.println("-----------------------------------------------------" //$NON-NLS-1$
+ "----------------"); //$NON-NLS-1$ + "----------------"); //$NON-NLS-1$
@ -335,9 +335,9 @@ class DiffAlgorithms extends TextBuiltin {
} }
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw die("Cannot determine names", e); throw die("Cannot determine names", e); //$NON-NLS-1$
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw die("Cannot determine names", e); throw die("Cannot determine names", e); //$NON-NLS-1$
} }
return all; return all;

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java

@ -167,7 +167,7 @@ class RebuildCommitGraph extends TextBuiltin {
} }
} }
pm.beginTask("Rewriting commits", queue.size()); pm.beginTask("Rewriting commits", queue.size()); //$NON-NLS-1$
try (ObjectInserter oi = db.newObjectInserter()) { try (ObjectInserter oi = db.newObjectInserter()) {
final ObjectId emptyTree = oi.insert(Constants.OBJ_TREE, final ObjectId emptyTree = oi.insert(Constants.OBJ_TREE,
new byte[] {}); new byte[] {});
@ -203,7 +203,7 @@ class RebuildCommitGraph extends TextBuiltin {
newc.setAuthor(new PersonIdent(me, new Date(t.commitTime))); newc.setAuthor(new PersonIdent(me, new Date(t.commitTime)));
newc.setCommitter(newc.getAuthor()); newc.setCommitter(newc.getAuthor());
newc.setParentIds(newParents); 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); t.newId = oi.insert(newc);
rewrites.put(t.oldId, t.newId); rewrites.put(t.oldId, t.newId);
pm.update(1); pm.update(1);

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java

@ -87,9 +87,9 @@ class ShowPackDelta extends TextBuiltin {
long size = reader.getObjectSize(obj, obj.getType()); long size = reader.getObjectSize(obj, obj.getType());
try { try {
if (BinaryDelta.getResultSize(delta) != size) 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) { } 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)); outw.println(BinaryDelta.format(delta));

8
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java

@ -349,10 +349,10 @@ class TextHashFunctions extends TextBuiltin {
name = parent.getName(); name = parent.getName();
outw.println(name + ":"); //$NON-NLS-1$ 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(fileCnt), //
valueOf(lineCnt / 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$ outw.println("-----------------------------------------------"); //$NON-NLS-1$
String lastHashName = null; String lastHashName = null;
for (Function fun : all) { for (Function fun : all) {
@ -405,9 +405,9 @@ class TextHashFunctions extends TextBuiltin {
} }
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new RuntimeException("Cannot determine names", e); throw new RuntimeException("Cannot determine names", e); //$NON-NLS-1$
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new RuntimeException("Cannot determine names", e); throw new RuntimeException("Cannot determine names", e); //$NON-NLS-1$
} }
List<Function> all = new ArrayList<Function>(); List<Function> all = new ArrayList<Function>();

12
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java

@ -109,7 +109,7 @@ public class AbstractTreeIteratorHandler extends
try { try {
dirc = DirCache.read(new File(name), FS.DETECTED); dirc = DirCache.read(new File(name), FS.DETECTED);
} catch (IOException e) { } 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)); setter.addValue(new DirCacheIterator(dirc));
return 1; return 1;
@ -119,20 +119,20 @@ public class AbstractTreeIteratorHandler extends
try { try {
id = clp.getRepository().resolve(name); id = clp.getRepository().resolve(name);
} catch (IOException e) { } catch (IOException e) {
throw new CmdLineException(e.getMessage()); throw new CmdLineException(clp, e.getMessage());
} }
if (id == null) 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(); final CanonicalTreeParser p = new CanonicalTreeParser();
try (ObjectReader curs = clp.getRepository().newObjectReader()) { try (ObjectReader curs = clp.getRepository().newObjectReader()) {
p.reset(curs, clp.getRevWalk().parseTree(id)); p.reset(curs, clp.getRevWalk().parseTree(id));
} catch (MissingObjectException e) { } 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) { } 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) { } 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); setter.addValue(p);

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/ObjectIdHandler.java

@ -86,14 +86,14 @@ public class ObjectIdHandler extends OptionHandler<ObjectId> {
try { try {
id = clp.getRepository().resolve(name); id = clp.getRepository().resolve(name);
} catch (IOException e) { } catch (IOException e) {
throw new CmdLineException(e.getMessage()); throw new CmdLineException(clp, e.getMessage());
} }
if (id != null) { if (id != null) {
setter.addValue(id); setter.addValue(id);
return 1; return 1;
} }
throw new CmdLineException(MessageFormat.format(CLIText.get().notAnObject, name)); throw new CmdLineException(clp, MessageFormat.format(CLIText.get().notAnObject, name));
} }
@Override @Override

16
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java

@ -96,8 +96,10 @@ public class RevCommitHandler extends OptionHandler<RevCommit> {
final int dot2 = name.indexOf(".."); //$NON-NLS-1$ final int dot2 = name.indexOf(".."); //$NON-NLS-1$
if (dot2 != -1) { if (dot2 != -1) {
if (!option.isMultiValued()) if (!option.isMultiValued())
throw new CmdLineException(MessageFormat.format(CLIText.get().onlyOneMetaVarExpectedIn throw new CmdLineException(clp,
, option.metaVar(), name)); MessageFormat.format(
CLIText.get().onlyOneMetaVarExpectedIn,
option.metaVar(), name));
final String left = name.substring(0, dot2); final String left = name.substring(0, dot2);
final String right = name.substring(dot2 + 2); final String right = name.substring(dot2 + 2);
@ -116,20 +118,20 @@ public class RevCommitHandler extends OptionHandler<RevCommit> {
try { try {
id = clp.getRepository().resolve(name); id = clp.getRepository().resolve(name);
} catch (IOException e) { } catch (IOException e) {
throw new CmdLineException(e.getMessage()); throw new CmdLineException(clp, e.getMessage());
} }
if (id == null) 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; final RevCommit c;
try { try {
c = clp.getRevWalk().parseCommit(id); c = clp.getRevWalk().parseCommit(id);
} catch (MissingObjectException e) { } 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) { } 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) { } 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) if (interesting)

10
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java

@ -89,20 +89,20 @@ public class RevTreeHandler extends OptionHandler<RevTree> {
try { try {
id = clp.getRepository().resolve(name); id = clp.getRepository().resolve(name);
} catch (IOException e) { } catch (IOException e) {
throw new CmdLineException(e.getMessage()); throw new CmdLineException(clp, e.getMessage());
} }
if (id == null) 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; final RevTree c;
try { try {
c = clp.getRevWalk().parseTree(id); c = clp.getRevWalk().parseTree(id);
} catch (MissingObjectException e) { } 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) { } 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) { } 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); setter.addValue(c);
return 1; return 1;

5
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/SubcommandHandler.java

@ -63,6 +63,8 @@ import org.eclipse.jgit.pgm.internal.CLIText;
* we can execute at runtime with the remaining arguments of the parser. * we can execute at runtime with the remaining arguments of the parser.
*/ */
public class SubcommandHandler extends OptionHandler<TextBuiltin> { public class SubcommandHandler extends OptionHandler<TextBuiltin> {
private final org.eclipse.jgit.pgm.opt.CmdLineParser clp;
/** /**
* Create a new handler for the command name. * Create a new handler for the command name.
* <p> * <p>
@ -75,6 +77,7 @@ public class SubcommandHandler extends OptionHandler<TextBuiltin> {
public SubcommandHandler(final CmdLineParser parser, public SubcommandHandler(final CmdLineParser parser,
final OptionDef option, final Setter<? super TextBuiltin> setter) { final OptionDef option, final Setter<? super TextBuiltin> setter) {
super(parser, option, setter); super(parser, option, setter);
clp = (org.eclipse.jgit.pgm.opt.CmdLineParser) parser;
} }
@Override @Override
@ -82,7 +85,7 @@ public class SubcommandHandler extends OptionHandler<TextBuiltin> {
final String name = params.getParameter(0); final String name = params.getParameter(0);
final CommandRef cr = CommandCatalog.get(name); final CommandRef cr = CommandCatalog.get(name);
if (cr == null) if (cr == null)
throw new CmdLineException(MessageFormat.format( throw new CmdLineException(clp, MessageFormat.format(
CLIText.get().notAJgitCommand, name)); CLIText.get().notAJgitCommand, name));
// Force option parsing to stop. Everything after us should // Force option parsing to stop. Everything after us should

66
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java

@ -104,37 +104,38 @@ public class BranchCommandTest extends RepositoryTestCase {
private Git setUpRepoWithRemote() throws Exception { private Git setUpRepoWithRemote() throws Exception {
Repository remoteRepository = createWorkRepository(); Repository remoteRepository = createWorkRepository();
Git remoteGit = new Git(remoteRepository); try (Git remoteGit = new Git(remoteRepository)) {
// commit something // commit something
writeTrashFile("Test.txt", "Hello world"); writeTrashFile("Test.txt", "Hello world");
remoteGit.add().addFilepattern("Test.txt").call(); remoteGit.add().addFilepattern("Test.txt").call();
initialCommit = remoteGit.commit().setMessage("Initial commit").call(); initialCommit = remoteGit.commit().setMessage("Initial commit").call();
writeTrashFile("Test.txt", "Some change"); writeTrashFile("Test.txt", "Some change");
remoteGit.add().addFilepattern("Test.txt").call(); remoteGit.add().addFilepattern("Test.txt").call();
secondCommit = remoteGit.commit().setMessage("Second commit").call(); secondCommit = remoteGit.commit().setMessage("Second commit").call();
// create a master branch // create a master branch
RefUpdate rup = remoteRepository.updateRef("refs/heads/master"); RefUpdate rup = remoteRepository.updateRef("refs/heads/master");
rup.setNewObjectId(initialCommit.getId()); rup.setNewObjectId(initialCommit.getId());
rup.forceUpdate(); rup.forceUpdate();
Repository localRepository = createWorkRepository(); Repository localRepository = createWorkRepository();
Git localGit = new Git(localRepository); Git localGit = new Git(localRepository);
StoredConfig config = localRepository.getConfig(); StoredConfig config = localRepository.getConfig();
RemoteConfig rc = new RemoteConfig(config, "origin"); RemoteConfig rc = new RemoteConfig(config, "origin");
rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath())); rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath()));
rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
rc.update(config); rc.update(config);
config.save(); config.save();
FetchResult res = localGit.fetch().setRemote("origin").call(); FetchResult res = localGit.fetch().setRemote("origin").call();
assertFalse(res.getTrackingRefUpdates().isEmpty()); assertFalse(res.getTrackingRefUpdates().isEmpty());
rup = localRepository.updateRef("refs/heads/master"); rup = localRepository.updateRef("refs/heads/master");
rup.setNewObjectId(initialCommit.getId()); rup.setNewObjectId(initialCommit.getId());
rup.forceUpdate(); rup.forceUpdate();
rup = localRepository.updateRef(Constants.HEAD); rup = localRepository.updateRef(Constants.HEAD);
rup.link("refs/heads/master"); rup.link("refs/heads/master");
rup.setNewObjectId(initialCommit.getId()); rup.setNewObjectId(initialCommit.getId());
rup.update(); rup.update();
return localGit; return localGit;
}
} }
@Test @Test
@ -192,8 +193,7 @@ public class BranchCommandTest extends RepositoryTestCase {
@Test @Test
public void testListAllBranchesShouldNotDie() throws Exception { public void testListAllBranchesShouldNotDie() throws Exception {
Git git = setUpRepoWithRemote(); setUpRepoWithRemote().branchList().setListMode(ListMode.ALL).call();
git.branchList().setListMode(ListMode.ALL).call();
} }
@Test @Test

97
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java

@ -417,20 +417,20 @@ public class CheckoutCommandTest extends RepositoryTestCase {
InvalidRemoteException, TransportException { InvalidRemoteException, TransportException {
// create second repository // create second repository
Repository db2 = createWorkRepository(); Repository db2 = createWorkRepository();
Git git2 = new Git(db2); try (Git git2 = new Git(db2)) {
// setup the second repository to fetch from the first repository
// setup the second repository to fetch from the first repository final StoredConfig config = db2.getConfig();
final StoredConfig config = db2.getConfig(); RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); URIish uri = new URIish(db.getDirectory().toURI().toURL());
URIish uri = new URIish(db.getDirectory().toURI().toURL()); remoteConfig.addURI(uri);
remoteConfig.addURI(uri); remoteConfig.update(config);
remoteConfig.update(config); config.save();
config.save();
// fetch from first repository
// fetch from first repository RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*"); git2.fetch().setRemote("origin").setRefSpecs(spec).call();
git2.fetch().setRemote("origin").setRefSpecs(spec).call(); return db2;
return db2; }
} }
private CheckoutCommand newOrphanBranchCommand() { private CheckoutCommand newOrphanBranchCommand() {
@ -639,40 +639,41 @@ public class CheckoutCommandTest extends RepositoryTestCase {
File clean_filter = writeTempFile("sed s/V1/@version/g -"); File clean_filter = writeTempFile("sed s/V1/@version/g -");
File smudge_filter = writeTempFile("sed s/@version/V1/g -"); File smudge_filter = writeTempFile("sed s/@version/V1/g -");
Git git = new Git(db); try (Git git2 = new Git(db)) {
StoredConfig config = git.getRepository().getConfig(); StoredConfig config = git.getRepository().getConfig();
config.setString("filter", "tstFilter", "smudge", config.setString("filter", "tstFilter", "smudge",
"sh " + slashify(smudge_filter.getPath())); "sh " + slashify(smudge_filter.getPath()));
config.setString("filter", "tstFilter", "clean", config.setString("filter", "tstFilter", "clean",
"sh " + slashify(clean_filter.getPath())); "sh " + slashify(clean_filter.getPath()));
config.save(); config.save();
writeTrashFile(".gitattributes", "*.txt filter=tstFilter"); writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
git.add().addFilepattern(".gitattributes").call(); git2.add().addFilepattern(".gitattributes").call();
git.commit().setMessage("add attributes").call(); git2.commit().setMessage("add attributes").call();
writeTrashFile("filterTest.txt", "hello world, V1"); writeTrashFile("filterTest.txt", "hello world, V1");
git.add().addFilepattern("filterTest.txt").call(); git2.add().addFilepattern("filterTest.txt").call();
git.commit().setMessage("add filterText.txt").call(); git2.commit().setMessage("add filterText.txt").call();
assertEquals( assertEquals(
"[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]", "[.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)); indexState(CONTENT));
git.checkout().setCreateBranch(true).setName("test2").call(); git2.checkout().setCreateBranch(true).setName("test2").call();
writeTrashFile("filterTest.txt", "bon giorno world, V1"); writeTrashFile("filterTest.txt", "bon giorno world, V1");
git.add().addFilepattern("filterTest.txt").call(); git2.add().addFilepattern("filterTest.txt").call();
git.commit().setMessage("modified filterText.txt").call(); git2.commit().setMessage("modified filterText.txt").call();
assertTrue(git.status().call().isClean()); assertTrue(git2.status().call().isClean());
assertEquals( 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]", "[.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)); indexState(CONTENT));
git.checkout().setName("refs/heads/test").call(); git2.checkout().setName("refs/heads/test").call();
assertTrue(git.status().call().isClean()); assertTrue(git2.status().call().isClean());
assertEquals( assertEquals(
"[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]", "[.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)); indexState(CONTENT));
assertEquals("hello world, V1", read("filterTest.txt")); assertEquals("hello world, V1", read("filterTest.txt"));
}
} }
private File writeTempFile(String body) throws IOException { private File writeTempFile(String body) throws IOException {

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java vendored

@ -69,6 +69,7 @@ public class DirCacheEntryTest {
assertFalse(isValidPath("a\u0000b")); assertFalse(isValidPath("a\u0000b"));
} }
@SuppressWarnings("unused")
private static boolean isValidPath(String path) { private static boolean isValidPath(String path) {
try { try {
new DirCacheEntry(path); new DirCacheEntry(path);
@ -78,6 +79,7 @@ public class DirCacheEntryTest {
} }
} }
@SuppressWarnings("unused")
@Test @Test
public void testCreate_ByStringPath() { public void testCreate_ByStringPath() {
assertEquals("a", new DirCacheEntry("a").getPathString()); assertEquals("a", new DirCacheEntry("a").getPathString());
@ -91,6 +93,7 @@ public class DirCacheEntryTest {
} }
} }
@SuppressWarnings("unused")
@Test @Test
public void testCreate_ByStringPathAndStage() { public void testCreate_ByStringPathAndStage() {
DirCacheEntry e; DirCacheEntry e;

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java

@ -72,6 +72,7 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
.findGitDir(d).getGitDir()); .findGitDir(d).getGitDir());
} }
@SuppressWarnings("unused")
@Test @Test
public void emptyRepositoryFormatVersion() throws Exception { public void emptyRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository(); Repository r = createWorkRepository();
@ -83,6 +84,7 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
new FileRepository(r.getDirectory()); new FileRepository(r.getDirectory());
} }
@SuppressWarnings("unused")
@Test @Test
public void invalidRepositoryFormatVersion() throws Exception { public void invalidRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository(); Repository r = createWorkRepository();
@ -99,6 +101,7 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
} }
} }
@SuppressWarnings("unused")
@Test @Test
public void unknownRepositoryFormatVersion() throws Exception { public void unknownRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository(); Repository r = createWorkRepository();

25
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java

@ -558,13 +558,15 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
assertEquals(ppid, db.resolve("refs/heads/master")); assertEquals(ppid, db.resolve("refs/heads/master"));
// real test // real test
RevCommit old = new RevWalk(db).parseCommit(ppid); try (RevWalk rw = new RevWalk(db)) {
RefUpdate updateRef2 = db.updateRef("refs/heads/master"); RevCommit old = rw.parseCommit(ppid);
updateRef2.setExpectedOldObjectId(old); RefUpdate updateRef2 = db.updateRef("refs/heads/master");
updateRef2.setNewObjectId(pid); updateRef2.setExpectedOldObjectId(old);
Result update2 = updateRef2.update(); updateRef2.setNewObjectId(pid);
assertEquals(Result.FAST_FORWARD, update2); Result update2 = updateRef2.update();
assertEquals(pid, db.resolve("refs/heads/master")); assertEquals(Result.FAST_FORWARD, update2);
assertEquals(pid, db.resolve("refs/heads/master"));
}
} }
/** /**
@ -707,9 +709,10 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
// Create new Repository instance, to reread caches and make sure our // Create new Repository instance, to reread caches and make sure our
// assumptions are persistent. // assumptions are persistent.
Repository ndb = new FileRepository(db.getDirectory()); try (Repository ndb = new FileRepository(db.getDirectory())) {
assertEquals(rb2, ndb.resolve("refs/heads/new/name")); assertEquals(rb2, ndb.resolve("refs/heads/new/name"));
assertNull(ndb.resolve("refs/heads/b")); assertNull(ndb.resolve("refs/heads/b"));
}
} }
public void tryRenameWhenLocked(String toLock, String fromName, public void tryRenameWhenLocked(String toLock, String fromName,
@ -751,7 +754,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
assertNull(db.resolve(toName)); assertNull(db.resolve(toName));
assertEquals(oldFromLog.toString(), db.getReflogReader(fromName) assertEquals(oldFromLog.toString(), db.getReflogReader(fromName)
.getReverseEntries().toString()); .getReverseEntries().toString());
if (oldHeadId != null) if (oldHeadId != null && oldHeadLog != null)
assertEquals(oldHeadLog.toString(), db.getReflogReader( assertEquals(oldHeadLog.toString(), db.getReflogReader(
Constants.HEAD).getReverseEntries().toString()); Constants.HEAD).getReverseEntries().toString());
} finally { } finally {

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java

@ -362,6 +362,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
assertNotSame(db.getConfig(), db2.getConfig()); assertNotSame(db.getConfig(), db2.getConfig());
} }
@SuppressWarnings("unused")
@Test @Test
public void test008_FailOnWrongVersion() throws IOException { public void test008_FailOnWrongVersion() throws IOException {
final File cfg = new File(db.getDirectory(), Constants.CONFIG); final File cfg = new File(db.getDirectory(), Constants.CONFIG);

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java

@ -75,11 +75,13 @@ public class T0001_PersonIdentTest {
p.toExternalString()); p.toExternalString());
} }
@SuppressWarnings("unused")
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void nullForNameShouldThrowIllegalArgumentException() { public void nullForNameShouldThrowIllegalArgumentException() {
new PersonIdent(null, "author@example.com"); new PersonIdent(null, "author@example.com");
} }
@SuppressWarnings("unused")
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void nullForEmailShouldThrowIllegalArgumentException() { public void nullForEmailShouldThrowIllegalArgumentException() {
new PersonIdent("A U Thor", null); new PersonIdent("A U Thor", null);

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java

@ -195,6 +195,7 @@ public class SideBandOutputStreamTest {
assertEquals(1, flushCnt[0]); assertEquals(1, flushCnt[0]);
} }
@SuppressWarnings("unused")
@Test @Test
public void testConstructor_RejectsBadChannel() { public void testConstructor_RejectsBadChannel() {
try { try {
@ -220,6 +221,7 @@ public class SideBandOutputStreamTest {
} }
} }
@SuppressWarnings("unused")
@Test @Test
public void testConstructor_RejectsBadBufferSize() { public void testConstructor_RejectsBadBufferSize() {
try { try {

48
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java

@ -51,7 +51,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -64,24 +63,16 @@ public class URIishTest {
private static final String GIT_SCHEME = "git://"; private static final String GIT_SCHEME = "git://";
@Test @SuppressWarnings("unused")
@Test(expected = URISyntaxException.class)
public void shouldRaiseErrorOnEmptyURI() throws Exception { public void shouldRaiseErrorOnEmptyURI() throws Exception {
try { new URIish("");
new URIish("");
fail("expecting an exception");
} catch (URISyntaxException e) {
// expected
}
} }
@Test @SuppressWarnings("unused")
@Test(expected = URISyntaxException.class)
public void shouldRaiseErrorOnNullURI() throws Exception { public void shouldRaiseErrorOnNullURI() throws Exception {
try { new URIish((String) null);
new URIish((String) null);
fail("expecting an exception");
} catch (URISyntaxException e) {
// expected
}
} }
@Test @Test
@ -634,34 +625,19 @@ public class URIishTest {
assertEquals(u, new URIish(str)); assertEquals(u, new URIish(str));
} }
@Test @Test(expected = IllegalArgumentException.class)
public void testGetNullHumanishName() { public void testGetNullHumanishName() {
try { new URIish().getHumanishName();
new URIish().getHumanishName();
fail("path must be not null");
} catch (IllegalArgumentException e) {
// expected
}
} }
@Test @Test(expected = IllegalArgumentException.class)
public void testGetEmptyHumanishName() throws URISyntaxException { public void testGetEmptyHumanishName() throws URISyntaxException {
try { new URIish(GIT_SCHEME).getHumanishName();
new URIish(GIT_SCHEME).getHumanishName();
fail("empty path is useless");
} catch (IllegalArgumentException e) {
// expected
}
} }
@Test @Test(expected = IllegalArgumentException.class)
public void testGetAbsEmptyHumanishName() { public void testGetAbsEmptyHumanishName() {
try { new URIish().getHumanishName();
new URIish().getHumanishName();
fail("empty path is useless");
} catch (IllegalArgumentException e) {
// expected
}
} }
@Test @Test

2
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

@ -179,7 +179,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
processOptions(state, rw); processOptions(state, rw);
if (all && !repo.isBare() && repo.getWorkTree() != null) { if (all && !repo.isBare()) {
try (Git git = new Git(repo)) { try (Git git = new Git(repo)) {
git.add() git.add()
.addFilepattern(".") //$NON-NLS-1$ .addFilepattern(".") //$NON-NLS-1$

2
org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

@ -715,7 +715,7 @@ public class URIish implements Serializable {
*/ */
public String getHumanishName() throws IllegalArgumentException { public String getHumanishName() throws IllegalArgumentException {
String s = getPath(); String s = getPath();
if ("/".equals(s) || "".equals(s)) //$NON-NLS-1$ if ("/".equals(s) || "".equals(s)) //$NON-NLS-1$ //$NON-NLS-2$
s = getHost(); s = getHost();
if (s == null) // $NON-NLS-1$ if (s == null) // $NON-NLS-1$
throw new IllegalArgumentException(); throw new IllegalArgumentException();

11
tools/version.sh

@ -144,17 +144,6 @@ perl -pi~ -e '
} }
' org.eclipse.jgit.packaging/org.*.feature/pom.xml ' 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>}{<${1}>'"$POM_V"'</${1}>};
}
' org.eclipse.jgit.packaging/org.eclipse.jgit.updatesite/pom.xml
perl -pi~ -e ' perl -pi~ -e '
if ($ARGV ne $old_argv) { if ($ARGV ne $old_argv) {
$seen_version = 0; $seen_version = 0;

Loading…
Cancel
Save