diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2011-05-31 09:14:50 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2011-05-31 09:15:11 -0700 |
commit | 690c268c793bfc218982130fbfc25870f292295e (patch) | |
tree | 2566abc3eb7c591ce2591129e90c8219615348a7 /org.eclipse.jgit.test/tst/org | |
parent | b04be9334494640a693ef5e515af1be4a6983eb5 (diff) | |
parent | 50f236aff861ab2a6851eb96cff6fe07b775bb5b (diff) | |
download | jgit-690c268c793bfc218982130fbfc25870f292295e.tar.gz jgit-690c268c793bfc218982130fbfc25870f292295e.zip |
Merge branch 'stable-1.0'
* stable-1.0:
DHT: Support removing a repository name
DHT: Fix thread-safety issue in AbstractWriteBuffer
jgit.sh: Implement pager support
Change EditList to extend ArrayList
Ensure the HTTP request is fully consumed
Make sure test repositories are closed
Fix CloneCommand not to fetch into remote tracking branches when bare
Update Eclipse IP log for 1.0
Change-Id: I6340d551482e1dda01f82496296d2038b07fa68b
Diffstat (limited to 'org.eclipse.jgit.test/tst/org')
5 files changed, 118 insertions, 4 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java index f21dc4a0be..2e3345756d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java @@ -49,12 +49,14 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; import java.util.Collections; +import java.util.List; import org.eclipse.jgit.api.ListBranchCommand.ListMode; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryTestCase; @@ -99,6 +101,7 @@ public class CloneCommandTest extends RepositoryTestCase { command.setURI("file://" + git.getRepository().getWorkTree().getPath()); Git git2 = command.call(); + addRepoToClose(git2.getRepository()); assertNotNull(git2); ObjectId id = git2.getRepository().resolve("tag-for-blob"); assertNotNull(id); @@ -133,9 +136,51 @@ public class CloneCommandTest extends RepositoryTestCase { command.setURI("file://" + git.getRepository().getWorkTree().getPath()); Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), + "refs/heads/master"); + assertEquals( + "refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test", + allRefNames(git2.branchList().setListMode(ListMode.ALL) + .call())); + + // Same thing, but now without checkout + directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); + command = Git.cloneRepository(); + command.setBranch("refs/heads/master"); + command.setDirectory(directory); + command.setURI("file://" + + git.getRepository().getWorkTree().getPath()); + command.setNoCheckout(true); + git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertNotNull(git2); assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); + assertEquals( + "refs/remotes/origin/master, refs/remotes/origin/test", + allRefNames(git2.branchList().setListMode(ListMode.ALL) + .call())); + + // Same thing, but now test with bare repo + directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); + command = Git.cloneRepository(); + command.setBranch("refs/heads/master"); + command.setDirectory(directory); + command.setURI("file://" + + git.getRepository().getWorkTree().getPath()); + command.setBare(true); + git2 = command.call(); + addRepoToClose(git2.getRepository()); + + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), + "refs/heads/master"); + assertEquals("refs/heads/master, refs/heads/test", allRefNames(git2 + .branchList().setListMode(ListMode.ALL).call())); } catch (Exception e) { fail(e.getMessage()); } @@ -153,16 +198,46 @@ public class CloneCommandTest extends RepositoryTestCase { command.setURI("file://" + git.getRepository().getWorkTree().getPath()); Git git2 = command.call(); + addRepoToClose(git2.getRepository()); assertNotNull(git2); assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); - assertEquals(1, git2.branchList().setListMode(ListMode.REMOTE) - .call().size()); + assertEquals("refs/remotes/origin/master", + allRefNames(git2.branchList() + .setListMode(ListMode.REMOTE).call())); + + // Same thing, but now test with bare repo + directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); + command = Git.cloneRepository(); + command.setBranch("refs/heads/master"); + command.setBranchesToClone(Collections + .singletonList("refs/heads/master")); + command.setDirectory(directory); + command.setURI("file://" + + git.getRepository().getWorkTree().getPath()); + command.setBare(true); + git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), + "refs/heads/master"); + assertEquals("refs/heads/master", allRefNames(git2 + .branchList().setListMode(ListMode.ALL).call())); } catch (Exception e) { fail(e.getMessage()); } } + public static String allRefNames(List<Ref> refs) { + StringBuilder sb = new StringBuilder(); + for (Ref f : refs) { + if (sb.length() > 0) + sb.append(", "); + sb.append(f.getName()); + } + return sb.toString(); + } + public static File createTempDirectory(String name) throws IOException { final File temp; temp = File.createTempFile(name, Long.toString(System.nanoTime())); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java index 8aacbb063c..8031769204 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java @@ -72,6 +72,7 @@ public class GitConstructionTest extends RepositoryTestCase { .setURI(db.getDirectory().toURI().toString()) .setDirectory(createUniqueTestGitDir(true)).call() .getRepository(); + addRepoToClose(bareRepo); } @Override @@ -88,7 +89,7 @@ public class GitConstructionTest extends RepositoryTestCase { assertEquals(1, git.branchList().call().size()); git = Git.wrap(bareRepo); - assertEquals(2, git.branchList().setListMode(ListMode.ALL).call() + assertEquals(1, git.branchList().setListMode(ListMode.ALL).call() .size()); try { @@ -105,7 +106,7 @@ public class GitConstructionTest extends RepositoryTestCase { assertEquals(1, git.branchList().call().size()); git = Git.open(bareRepo.getDirectory()); - assertEquals(2, git.branchList().setListMode(ListMode.ALL).call() + assertEquals(1, git.branchList().setListMode(ListMode.ALL).call() .size()); git = Git.open(db.getWorkTree()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java index 15aafc9060..28c54c269f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java @@ -70,6 +70,7 @@ public class InitCommandTest extends RepositoryTestCase { InitCommand command = new InitCommand(); command.setDirectory(directory); Repository repository = command.call().getRepository(); + addRepoToClose(repository); assertNotNull(repository); } catch (Exception e) { fail(e.getMessage()); @@ -84,6 +85,7 @@ public class InitCommandTest extends RepositoryTestCase { command.setDirectory(directory); command.setBare(true); Repository repository = command.call().getRepository(); + addRepoToClose(repository); assertNotNull(repository); assertTrue(repository.isBare()); } catch (Exception e) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java index 81aa25f981..a4a5a2671b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java @@ -89,6 +89,8 @@ public class LsRemoteCommandTest extends RepositoryTestCase { + git.getRepository().getWorkTree().getPath()); command.setCloneAllBranches(true); Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + LsRemoteCommand lsRemoteCommand = git2.lsRemote(); Collection<Ref> refs = lsRemoteCommand.call(); @@ -109,6 +111,7 @@ public class LsRemoteCommandTest extends RepositoryTestCase { + git.getRepository().getWorkTree().getPath()); command.setCloneAllBranches(true); Git git2 = command.call(); + addRepoToClose(git2.getRepository()); LsRemoteCommand lsRemoteCommand = git2.lsRemote(); lsRemoteCommand.setTags(true); @@ -130,6 +133,7 @@ public class LsRemoteCommandTest extends RepositoryTestCase { + git.getRepository().getWorkTree().getPath()); command.setCloneAllBranches(true); Git git2 = command.call(); + addRepoToClose(git2.getRepository()); LsRemoteCommand lsRemoteCommand = git2.lsRemote(); lsRemoteCommand.setHeads(true); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java index df89674e6f..719cc66671 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java @@ -46,7 +46,9 @@ package org.eclipse.jgit.transport; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.File; @@ -54,8 +56,10 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.MessageDigest; +import java.text.MessageFormat; import java.util.zip.Deflater; +import org.eclipse.jgit.JGitText; import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.Constants; @@ -69,6 +73,7 @@ import org.eclipse.jgit.storage.file.ObjectDirectoryPackParser; import org.eclipse.jgit.storage.file.PackFile; import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.TemporaryBuffer; +import org.eclipse.jgit.util.io.UnionInputStream; import org.junit.After; import org.junit.Test; @@ -177,6 +182,33 @@ public class PackParserTest extends RepositoryTestCase { p.parse(NullProgressMonitor.INSTANCE); } + @Test + public void testPackWithTrailingGarbage() throws Exception { + TestRepository d = new TestRepository(db); + RevBlob a = d.blob("a"); + + TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); + packHeader(pack, 1); + pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + a.copyRawTo(pack); + deflate(pack, new byte[] { 0x1, 0x1, 0x1, 'b' }); + digest(pack); + + PackParser p = index(new UnionInputStream( + new ByteArrayInputStream(pack.toByteArray()), + new ByteArrayInputStream(new byte[] { 0x7e }))); + p.setAllowThin(true); + p.setCheckEofAfterPackFooter(true); + try { + p.parse(NullProgressMonitor.INSTANCE); + fail("Pack with trailing garbage was accepted"); + } catch (IOException err) { + assertEquals( + MessageFormat.format(JGitText.get().expectedEOFReceived, "\\x73"), + err.getMessage()); + } + } + private void packHeader(TemporaryBuffer.Heap tinyPack, int cnt) throws IOException { final byte[] hdr = new byte[8]; |