コード例 #1
0
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    src = createBareRepository();
    dst = createBareRepository();

    // Fill dst with a some common history.
    //
    TestRepository<Repository> d = new TestRepository<Repository>(dst);
    a = d.blob("a");
    A = d.commit(d.tree(d.file("a", a)));
    B = d.commit().parent(A).create();
    d.update(R_MASTER, B);

    // Clone from dst into src
    //
    Transport t = Transport.open(src, uriOf(dst));
    try {
      t.fetch(PM, Collections.singleton(new RefSpec("+refs/*:refs/*")));
      assertEquals(B, src.resolve(R_MASTER));
    } finally {
      t.close();
    }

    // Now put private stuff into dst.
    //
    b = d.blob("b");
    P = d.commit(d.tree(d.file("b", b)), A);
    d.update(R_PRIVATE, P);
  }
コード例 #2
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    final TestRepository<Repository> src = createTestRepository();
    final String srcName = src.getRepository().getDirectory().getName();

    ServletContextHandler app = server.addContext("/git");
    GitServlet gs = new GitServlet();
    gs.setRepositoryResolver(
        new RepositoryResolver<HttpServletRequest>() {
          public Repository open(HttpServletRequest req, String name)
              throws RepositoryNotFoundException, ServiceNotEnabledException {
            if (!name.equals(srcName)) throw new RepositoryNotFoundException(name);

            final Repository db = src.getRepository();
            db.incrementOpen();
            return db;
          }
        });
    app.addServlet(new ServletHolder(gs), "/*");

    server.setUp();

    remoteRepository = src.getRepository();
    remoteURI = toURIish(app, srcName);

    A_txt = src.blob("A");
    A = src.commit().add("A_txt", A_txt).create();
    B = src.commit().parent(A).add("A_txt", "C").add("B", "B").create();
    src.update(master, B);
  }
コード例 #3
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    final TestRepository<FileRepository> src = createTestRepository();
    final String srcName = src.getRepository().getDirectory().getName();

    ServletContextHandler app = server.addContext("/git");
    GitServlet gs = new GitServlet();
    gs.setRepositoryResolver(
        new RepositoryResolver<HttpServletRequest>() {
          public Repository open(HttpServletRequest req, String name)
              throws RepositoryNotFoundException, ServiceNotEnabledException {
            if (!name.equals(srcName)) throw new RepositoryNotFoundException(name);

            final Repository db = src.getRepository();
            db.incrementOpen();
            return db;
          }
        });
    app.addServlet(new ServletHolder(gs), "/*");

    server.setUp();

    remoteRepository = src.getRepository();
    remoteURI = toURIish(app, srcName);

    FileBasedConfig cfg = remoteRepository.getConfig();
    cfg.setBoolean("http", null, "receivepack", true);
    cfg.save();

    a_blob = src.blob("a");
  }
コード例 #4
0
 @Test
 public void treeAndBlobTime() throws Exception {
   RevBlob blob = repo.blob("contents");
   RevTree tree = repo.tree(repo.file("foo", blob));
   assertThat(getTime(blob)).isEqualTo(Long.MIN_VALUE);
   assertThat(getTime(tree)).isEqualTo(Long.MIN_VALUE);
 }
コード例 #5
0
  @Test
  public void testUsingHiddenDeltaBaseFails() throws Exception {
    byte[] delta = {0x1, 0x1, 0x1, 'c'};
    TestRepository<Repository> s = new TestRepository<Repository>(src);
    RevCommit N =
        s.commit()
            .parent(B)
            .add("q", s.blob(BinaryDelta.apply(dst.open(b).getCachedBytes(), delta)))
            .create();

    final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
    packHeader(pack, 3);
    copy(pack, src.open(N));
    copy(pack, src.open(s.parseBody(N).getTree()));
    pack.write((Constants.OBJ_REF_DELTA) << 4 | 4);
    b.copyRawTo(pack);
    deflate(pack, delta);
    digest(pack);

    final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024);
    final PacketLineOut inPckLine = new PacketLineOut(inBuf);
    inPckLine.writeString(
        ObjectId.zeroId().name()
            + ' '
            + N.name()
            + ' '
            + "refs/heads/s"
            + '\0'
            + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
    inPckLine.end();
    pack.writeTo(inBuf, PM);

    final TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
    final ReceivePack rp = new ReceivePack(dst);
    rp.setCheckReceivedObjects(true);
    rp.setCheckReferencedObjectsAreReachable(true);
    rp.setAdvertiseRefsHook(new HidePrivateHook());
    try {
      receive(rp, inBuf, outBuf);
      fail("Expected UnpackException");
    } catch (UnpackException failed) {
      Throwable err = failed.getCause();
      assertTrue(err instanceof MissingObjectException);
      MissingObjectException moe = (MissingObjectException) err;
      assertEquals(b, moe.getObjectId());
    }

    final PacketLineIn r = asPacketLineIn(outBuf);
    String master = r.readString();
    int nul = master.indexOf('\0');
    assertTrue("has capability list", nul > 0);
    assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul));
    assertSame(PacketLineIn.END, r.readString());

    assertEquals("unpack error Missing blob " + b.name(), r.readString());
    assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString());
    assertSame(PacketLineIn.END, r.readString());
  }
コード例 #6
0
  @Test
  public void testUsingUnknownBlobFails() throws Exception {
    // Try to use the 'n' blob that is not on the server.
    //
    TestRepository<Repository> s = new TestRepository<Repository>(src);
    RevBlob n = s.blob("n");
    RevCommit N = s.commit().parent(B).add("q", n).create();

    // But don't include it in the pack.
    //
    final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
    packHeader(pack, 2);
    copy(pack, src.open(N));
    copy(pack, src.open(s.parseBody(N).getTree()));
    digest(pack);

    final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024);
    final PacketLineOut inPckLine = new PacketLineOut(inBuf);
    inPckLine.writeString(
        ObjectId.zeroId().name()
            + ' '
            + N.name()
            + ' '
            + "refs/heads/s"
            + '\0'
            + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
    inPckLine.end();
    pack.writeTo(inBuf, PM);

    final TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
    final ReceivePack rp = new ReceivePack(dst);
    rp.setCheckReceivedObjects(true);
    rp.setCheckReferencedObjectsAreReachable(true);
    rp.setAdvertiseRefsHook(new HidePrivateHook());
    try {
      receive(rp, inBuf, outBuf);
      fail("Expected UnpackException");
    } catch (UnpackException failed) {
      Throwable err = failed.getCause();
      assertTrue(err instanceof MissingObjectException);
      MissingObjectException moe = (MissingObjectException) err;
      assertEquals(n, moe.getObjectId());
    }

    final PacketLineIn r = asPacketLineIn(outBuf);
    String master = r.readString();
    int nul = master.indexOf('\0');
    assertTrue("has capability list", nul > 0);
    assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul));
    assertSame(PacketLineIn.END, r.readString());

    assertEquals("unpack error Missing blob " + n.name(), r.readString());
    assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString());
    assertSame(PacketLineIn.END, r.readString());
  }
コード例 #7
0
 @Test
 public void taggedTreeAndBlobTime() throws Exception {
   RevBlob blob = repo.blob("contents");
   RevTree tree = repo.tree(repo.file("foo", blob));
   repo.tick(1);
   RevTag blobTag = repo.tag("blob", blob);
   repo.tick(1);
   RevTag treeTag = repo.tag("tree", tree);
   assertThat(getTime(blobTag)).isEqualTo(start + 1);
   assertThat(getTime(treeTag)).isEqualTo(start + 2);
 }
コード例 #8
0
ファイル: AbbreviationTest.java プロジェクト: adityavs/jgit
  @Test
  public void testAbbreviateLooseBlob() throws Exception {
    ObjectId id = test.blob("test");

    assertEquals(id.abbreviate(2), reader.abbreviate(id, 2));
    assertEquals(id.abbreviate(7), reader.abbreviate(id, 7));
    assertEquals(id.abbreviate(8), reader.abbreviate(id, 8));
    assertEquals(id.abbreviate(10), reader.abbreviate(id, 10));
    assertEquals(id.abbreviate(16), reader.abbreviate(id, 16));

    Collection<ObjectId> matches = reader.resolve(reader.abbreviate(id, 8));
    assertNotNull(matches);
    assertEquals(1, matches.size());
    assertEquals(id, matches.iterator().next());

    assertEquals(id, db.resolve(reader.abbreviate(id, 8).name()));
  }
コード例 #9
0
ファイル: AbbreviationTest.java プロジェクト: adityavs/jgit
  @Test
  public void testAbbreviatePackedBlob() throws Exception {
    RevBlob id = test.blob("test");
    test.branch("master").commit().add("test", id).child();
    test.packAndPrune();
    assertTrue(reader.has(id));

    assertEquals(id.abbreviate(7), reader.abbreviate(id, 7));
    assertEquals(id.abbreviate(8), reader.abbreviate(id, 8));
    assertEquals(id.abbreviate(10), reader.abbreviate(id, 10));
    assertEquals(id.abbreviate(16), reader.abbreviate(id, 16));

    Collection<ObjectId> matches = reader.resolve(reader.abbreviate(id, 8));
    assertNotNull(matches);
    assertEquals(1, matches.size());
    assertEquals(id, matches.iterator().next());

    assertEquals(id, db.resolve(reader.abbreviate(id, 8).name()));
  }
コード例 #10
0
  private void generateSampleData(int n) throws Exception {
    A_txt = src.blob("A");
    A = src.commit().add(A_txt_name, A_txt).create();
    src.update(Constants.R_HEADS + Constants.MASTER, A);

    // create some random commits
    RevCommit X = A;
    for (int i = 0; i < n; i++) {
      X = src.commit().parent(X).add(randomAsciiString(), randomAsciiString()).create();
    }

    B = src.commit().parent(X).add(A_txt_name, "C").add("B", "B").create();
    src.update(Constants.R_HEADS + Constants.MASTER, B);

    v1_0 = src.tag(v1_0_name, B);
    src.update(Constants.R_TAGS + v1_0_name, v1_0);

    C = src.commit().parent(A).add(A_txt_name, "D").add("C", "C").create();
    src.update(Constants.R_HEADS + FIX, C);

    v2_0 = src.tag(v2_0_name, C);
    src.update(Constants.R_TAGS + v2_0_name, v2_0);
  }