コード例 #1
0
 @Test
 public void commitTime() throws Exception {
   RevCommit root = repo.commit().create();
   RevCommit master = repo.commit().parent(root).create();
   assertThat(getTime(root)).isEqualTo(start + 1);
   assertThat(getTime(master)).isEqualTo(start + 2);
 }
コード例 #2
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);
  }
コード例 #3
0
  @Test
  public void bySize() throws Exception {
    TestRepository<Repo> repo = createProject("repo");

    // added = 3, deleted = 0, delta = 3
    RevCommit commit1 = repo.parseBody(repo.commit().add("file1", "foo\n\foo\nfoo").create());
    // added = 0, deleted = 2, delta = 2
    RevCommit commit2 = repo.parseBody(repo.commit().parent(commit1).add("file1", "foo").create());

    Change change1 = newChange(repo, commit1, null, null, null).insert();
    Change change2 = newChange(repo, commit2, null, null, null).insert();

    assertQuery("added:>4");
    assertQuery("-added:<=4");

    assertQuery("added:3", change1);
    assertQuery("-(added:<3 OR added>3)", change1);

    assertQuery("added:>2", change1);
    assertQuery("-added:<=2", change1);

    assertQuery("added:>=3", change1);
    assertQuery("-added:<3", change1);

    assertQuery("added:<1", change2);
    assertQuery("-added:>=1", change2);

    assertQuery("added:<=0", change2);
    assertQuery("-added:>0", change2);

    assertQuery("deleted:>3");
    assertQuery("-deleted:<=3");

    assertQuery("deleted:2", change2);
    assertQuery("-(deleted:<2 OR deleted>2)", change2);

    assertQuery("deleted:>1", change2);
    assertQuery("-deleted:<=1", change2);

    assertQuery("deleted:>=2", change2);
    assertQuery("-deleted:<2", change2);

    assertQuery("deleted:<1", change1);
    assertQuery("-deleted:>=1", change1);

    assertQuery("deleted:<=0", change1);

    for (String str : Lists.newArrayList("delta", "size")) {
      assertQuery(str + ":<2");
      assertQuery(str + ":3", change1);
      assertQuery(str + ":>2", change1);
      assertQuery(str + ":>=3", change1);
      assertQuery(str + ":<3", change2);
      assertQuery(str + ":<=2", change2);
    }
  }
コード例 #4
0
  @Test
  public void fullTextWithNumbers() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    RevCommit commit1 = repo.parseBody(repo.commit().message("12345 67890").create());
    Change change1 = newChange(repo, commit1, null, null, null).insert();
    RevCommit commit2 = repo.parseBody(repo.commit().message("12346 67891").create());
    Change change2 = newChange(repo, commit2, null, null, null).insert();

    assertQuery("message:1234");
    assertQuery("message:12345", change1);
    assertQuery("message:12346", change2);
  }
コード例 #5
0
  @Test
  public void byMessageExact() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    RevCommit commit1 = repo.parseBody(repo.commit().message("one").create());
    Change change1 = newChange(repo, commit1, null, null, null).insert();
    RevCommit commit2 = repo.parseBody(repo.commit().message("two").create());
    Change change2 = newChange(repo, commit2, null, null, null).insert();

    assertQuery("message:foo");
    assertQuery("message:one", change1);
    assertQuery("message:two", change2);
  }
コード例 #6
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);
  }
コード例 #7
0
 @Test
 public void taggedCommitTime() throws Exception {
   RevCommit commit = repo.commit().create();
   repo.tick(1);
   RevTag tag = repo.tag("tag", commit);
   assertThat(getTime(commit)).isEqualTo(start + 1);
   assertThat(getTime(tag)).isEqualTo(start + 2);
 }
コード例 #8
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());
  }
コード例 #9
0
 @Test
 public void taggedTagTime() throws Exception {
   repo.tick(2);
   RevTag tag = repo.tag("tag", repo.commit().create());
   repo.tick(-1);
   RevTag tagTag = repo.tag("tagtag", tag);
   assertThat(getTime(tag)).isEqualTo(start + 3);
   assertThat(getTime(tagTag)).isEqualTo(start + 2);
 }
コード例 #10
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());
  }
コード例 #11
0
ファイル: GcTestCase.java プロジェクト: eclipse/jgit
 /**
  * Create a chain of commits of given depth.
  *
  * <p>Each commit contains one file named "a" containing the index of the commit in the chain as
  * its content. The created commit chain is referenced from any ref.
  *
  * <p>A chain of depth = N will create 3*N objects in Gits object database. For each depth level
  * three objects are created: the commit object, the top-level tree object and a blob for the
  * content of the file "a".
  *
  * @param depth the depth of the commit chain.
  * @return the commit that is the tip of the commit chain
  * @throws Exception
  */
 protected RevCommit commitChain(int depth) throws Exception {
   if (depth <= 0) throw new IllegalArgumentException("Chain depth must be > 0");
   CommitBuilder cb = tr.commit();
   RevCommit tip;
   do {
     --depth;
     tip = cb.add("a", "" + depth).message("" + depth).create();
     cb = cb.child();
   } while (depth > 0);
   return tip;
 }
コード例 #12
0
  @Test
  public void byDefault() throws Exception {
    TestRepository<Repo> repo = createProject("repo");

    Change change1 = newChange(repo, null, null, null, null).insert();

    RevCommit commit2 = repo.parseBody(repo.commit().message("foosubject").create());
    Change change2 = newChange(repo, commit2, null, null, null).insert();

    RevCommit commit3 = repo.parseBody(repo.commit().add("Foo.java", "foo contents").create());
    Change change3 = newChange(repo, commit3, null, null, null).insert();

    ChangeInserter ins4 = newChange(repo, null, null, null, null);
    Change change4 = ins4.insert();
    ReviewInput ri4 = new ReviewInput();
    ri4.message = "toplevel";
    ri4.labels = ImmutableMap.<String, Short>of("Code-Review", (short) 1);
    gApi.changes().id(change4.getId().get()).current().review(ri4);

    ChangeInserter ins5 = newChange(repo, null, null, null, null);
    Change change5 = ins5.getChange();
    change5.setTopic("feature5");
    ins5.insert();

    Change change6 = newChange(repo, null, null, null, "branch6").insert();

    assertQuery(change1.getId().get(), change1);
    assertQuery(ChangeTriplet.format(change1), change1);
    assertQuery("foosubject", change2);
    assertQuery("Foo.java", change3);
    assertQuery("Code-Review+1", change4);
    assertQuery("toplevel", change4);
    assertQuery("feature5", change5);
    assertQuery("branch6", change6);
    assertQuery("refs/heads/branch6", change6);

    Change[] expected = new Change[] {change6, change5, change4, change3, change2, change1};
    assertQuery("*****@*****.**", expected);
    assertQuery("repo", expected);
  }
コード例 #13
0
 protected Change newPatchSet(TestRepository<Repo> repo, Change c) throws Exception {
   // Add a new file so the patch set is not a trivial rebase, to avoid default
   // Code-Review label copying.
   int n = c.currentPatchSetId().get() + 1;
   RevCommit commit =
       repo.parseBody(repo.commit().message("message").add("file" + n, "contents " + n).create());
   ChangeControl ctl = changeControlFactory.controlFor(c.getId(), user);
   return patchSetFactory
       .create(repo.getRepository(), repo.getRevWalk(), ctl, commit)
       .setSendMail(false)
       .setRunHooks(false)
       .setValidatePolicy(ValidatePolicy.NONE)
       .insert();
 }
コード例 #14
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);
  }
コード例 #15
0
  @Test
  public void conflicts() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    RevCommit commit1 =
        repo.parseBody(
            repo.commit()
                .add("file1", "contents1")
                .add("dir/file2", "contents2")
                .add("dir/file3", "contents3")
                .create());
    RevCommit commit2 = repo.parseBody(repo.commit().add("file1", "contents1").create());
    RevCommit commit3 =
        repo.parseBody(repo.commit().add("dir/file2", "contents2 different").create());
    RevCommit commit4 = repo.parseBody(repo.commit().add("file4", "contents4").create());
    Change change1 = newChange(repo, commit1, null, null, null).insert();
    Change change2 = newChange(repo, commit2, null, null, null).insert();
    Change change3 = newChange(repo, commit3, null, null, null).insert();
    Change change4 = newChange(repo, commit4, null, null, null).insert();

    assertQuery("conflicts:" + change1.getId().get(), change3);
    assertQuery("conflicts:" + change2.getId().get());
    assertQuery("conflicts:" + change3.getId().get(), change1);
    assertQuery("conflicts:" + change4.getId().get());
  }
コード例 #16
0
  @Test
  public void byPathRegex() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    RevCommit commit =
        repo.parseBody(
            repo.commit()
                .message("one")
                .add("dir/file1", "contents1")
                .add("dir/file2", "contents2")
                .create());
    Change change = newChange(repo, commit, null, null, null).insert();

    assertQuery("path:.*file.*");
    assertQuery("path:^dir.file.*", change);
  }
コード例 #17
0
 @Test
 public void tagMissingTime() throws Exception {
   RevCommit commit = repo.commit().create();
   TagBuilder builder = new TagBuilder();
   builder.setObjectId(commit);
   builder.setTag("tag");
   builder.setMessage("");
   ObjectId id;
   try (ObjectInserter ins = repo.getRepository().newObjectInserter()) {
     id = ins.insert(builder);
     ins.flush();
   }
   assertThat(getTime(commit)).isEqualTo(start + 1);
   assertThat(getTime(id)).isEqualTo(start + 1);
 }
コード例 #18
0
ファイル: ViewFilterTest.java プロジェクト: candylin/gitiles
  public void testAutoCommand() throws Exception {
    RevCommit parent = repo.commit().create();
    RevCommit master = repo.branch("refs/heads/master").commit().parent(parent).create();
    String hex = master.name();
    String hexBranch = hex.substring(0, 10);
    RevCommit hexCommit = repo.branch(hexBranch).commit().create();

    assertEquals(Type.LOG, getView("/repo/+/master").getType());
    assertEquals(Type.LOG, getView("/repo/+/" + hexBranch).getType());
    assertEquals(Type.REVISION, getView("/repo/+/" + hex).getType());
    assertEquals(Type.REVISION, getView("/repo/+/" + hex.substring(0, 7)).getType());
    assertEquals(Type.PATH, getView("/repo/+/master/").getType());
    assertEquals(Type.PATH, getView("/repo/+/" + hex + "/").getType());
    assertEquals(Type.DIFF, getView("/repo/+/master^..master").getType());
    assertEquals(Type.DIFF, getView("/repo/+/master^..master/").getType());
    assertEquals(Type.DIFF, getView("/repo/+/" + parent.name() + ".." + hex + "/").getType());
  }
コード例 #19
0
  protected ChangeInserter newChange(
      TestRepository<Repo> repo,
      @Nullable RevCommit commit,
      @Nullable String key,
      @Nullable Integer owner,
      @Nullable String branch)
      throws Exception {
    if (commit == null) {
      commit = repo.parseBody(repo.commit().message("message").create());
    }
    Account.Id ownerId = owner != null ? new Account.Id(owner) : userId;
    branch = MoreObjects.firstNonNull(branch, "refs/heads/master");
    if (!branch.startsWith("refs/heads/")) {
      branch = "refs/heads/" + branch;
    }
    Project.NameKey project =
        new Project.NameKey(repo.getRepository().getDescription().getRepositoryName());

    Change.Id id = new Change.Id(db.nextChangeId());
    if (key == null) {
      key =
          "I"
              + Hashing.sha1()
                  .newHasher()
                  .putInt(id.get())
                  .putString(project.get(), UTF_8)
                  .putString(commit.name(), UTF_8)
                  .putInt(ownerId.get())
                  .putString(branch, UTF_8)
                  .hash()
                  .toString();
    }

    Change change =
        new Change(
            new Change.Key(key),
            id,
            ownerId,
            new Branch.NameKey(project, branch),
            TimeUtil.nowTs());
    IdentifiedUser user = userFactory.create(Providers.of(db), ownerId);
    return changeFactory.create(projectControlFactory.controlFor(project, user), change, commit);
  }
コード例 #20
0
  @Test
  public void testPushNotSupported() throws Exception {
    final TestRepository src = createTestRepository();
    final RevCommit Q = src.commit().create();
    final Repository db = src.getRepository();

    Transport t = Transport.open(db, remoteURI);
    ((TransportHttp) t).setUseSmartHttp(false);
    try {
      try {
        t.push(NullProgressMonitor.INSTANCE, push(src, Q));
        fail("push incorrectly completed against a smart server");
      } catch (NotSupportedException nse) {
        String exp = "smart HTTP push disabled";
        assertEquals(exp, nse.getMessage());
      }
    } finally {
      t.close();
    }
  }
コード例 #21
0
ファイル: GcTestCase.java プロジェクト: eclipse/jgit
 /**
  * Create a chain of commits of given depth with given number of added files per commit.
  *
  * <p>Each commit contains {@code files} files as its content. The created commit chain is
  * referenced from any ref.
  *
  * <p>A chain will create {@code (2 + files) * depth} objects in Gits object database. For each
  * depth level the following objects are created: the commit object, the top-level tree object
  * and @code files} blobs for the content of the file "a".
  *
  * @param depth the depth of the commit chain.
  * @param width number of files added per commit
  * @return the commit that is the tip of the commit chain
  * @throws Exception
  */
 protected RevCommit commitChain(int depth, int width) throws Exception {
   if (depth <= 0) {
     throw new IllegalArgumentException("Chain depth must be > 0");
   }
   if (width <= 0) {
     throw new IllegalArgumentException("Number of files per commit must be > 0");
   }
   CommitBuilder cb = tr.commit();
   RevCommit tip = null;
   do {
     --depth;
     for (int i = 0; i < width; i++) {
       String id = depth + "-" + i;
       cb.add("a" + id, id).message(id);
     }
     tip = cb.create();
     cb = cb.child();
   } while (depth > 0);
   return tip;
 }
コード例 #22
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    remoteRepository = createTestRepository();
    remoteRepository.update(master, remoteRepository.commit().create());

    ServletContextHandler dNone = dumb("/dnone");
    ServletContextHandler dBasic = server.authBasic(dumb("/dbasic"));

    ServletContextHandler sNone = smart("/snone");
    ServletContextHandler sBasic = server.authBasic(smart("/sbasic"));

    server.setUp();

    final String srcName = nameOf(remoteRepository.getRepository());
    dumbAuthNoneURI = toURIish(dNone, srcName);
    dumbAuthBasicURI = toURIish(dBasic, srcName);

    smartAuthNoneURI = toURIish(sNone, srcName);
    smartAuthBasicURI = toURIish(sBasic, srcName);
  }
コード例 #23
0
ファイル: ViewFilterTest.java プロジェクト: candylin/gitiles
  public void testDiff() throws Exception {
    RevCommit parent = repo.commit().create();
    RevCommit master = repo.branch("refs/heads/master").commit().parent(parent).create();
    GitilesView view;

    view = getView("/repo/+diff/master^..master");
    assertEquals(Type.DIFF, view.getType());
    assertEquals("master", view.getRevision().getName());
    assertEquals(master, view.getRevision().getId());
    assertEquals("master^", view.getOldRevision().getName());
    assertEquals(parent, view.getOldRevision().getId());
    assertEquals("", view.getTreePath());

    view = getView("/repo/+diff/master^..master/");
    assertEquals(Type.DIFF, view.getType());
    assertEquals("master", view.getRevision().getName());
    assertEquals(master, view.getRevision().getId());
    assertEquals("master^", view.getOldRevision().getName());
    assertEquals(parent, view.getOldRevision().getId());
    assertEquals("", view.getTreePath());

    view = getView("/repo/+diff/master^..master/foo");
    assertEquals(Type.DIFF, view.getType());
    assertEquals("master", view.getRevision().getName());
    assertEquals(master, view.getRevision().getId());
    assertEquals("master^", view.getOldRevision().getName());
    assertEquals(parent, view.getOldRevision().getId());
    assertEquals("foo", view.getTreePath());

    view = getView("/repo/+diff/refs/heads/master^..refs/heads/master");
    assertEquals(Type.DIFF, view.getType());
    assertEquals("refs/heads/master", view.getRevision().getName());
    assertEquals(master, view.getRevision().getId());
    assertEquals("refs/heads/master^", view.getOldRevision().getName());
    assertEquals(parent, view.getOldRevision().getId());
    assertEquals("", view.getTreePath());
  }
コード例 #24
0
  @Test
  public void testListRemote_Smart_DetachedHEAD() throws Exception {
    Repository src = remoteRepository.getRepository();
    RefUpdate u = src.updateRef(Constants.HEAD, true);
    RevCommit Q = remoteRepository.commit().message("Q").create();
    u.setNewObjectId(Q);
    assertEquals(RefUpdate.Result.FORCED, u.forceUpdate());

    Repository dst = createBareRepository();
    Ref head;
    Transport t = Transport.open(dst, smartAuthNoneURI);
    try {
      FetchConnection c = t.openFetch();
      try {
        head = c.getRef(Constants.HEAD);
      } finally {
        c.close();
      }
    } finally {
      t.close();
    }
    assertNotNull("has " + Constants.HEAD, head);
    assertEquals(Q, head.getObjectId());
  }
コード例 #25
0
  @Test
  public void testSuccess() throws Exception {
    // Manually force a delta of an object so we reuse it later.
    //
    TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);

    packHeader(pack, 2);
    pack.write((Constants.OBJ_BLOB) << 4 | 1);
    deflate(pack, new byte[] {'a'});

    pack.write((Constants.OBJ_REF_DELTA) << 4 | 4);
    a.copyRawTo(pack);
    deflate(pack, new byte[] {0x1, 0x1, 0x1, 'b'});

    digest(pack);
    openPack(pack);

    // Verify the only storage of b is our packed delta above.
    //
    ObjectDirectory od = (ObjectDirectory) src.getObjectDatabase();
    assertTrue("has b", src.hasObject(b));
    assertFalse("b not loose", od.fileFor(b).exists());

    // Now use b but in a different commit than what is hidden.
    //
    TestRepository<Repository> s = new TestRepository<Repository>(src);
    RevCommit N = s.commit().parent(B).add("q", b).create();
    s.update(R_MASTER, N);

    // Push this new content to the remote, doing strict validation.
    //
    TransportLocal t =
        new TransportLocal(src, uriOf(dst), dst.getDirectory()) {
          @Override
          ReceivePack createReceivePack(final Repository db) {
            db.close();
            dst.incrementOpen();

            final ReceivePack rp = super.createReceivePack(dst);
            rp.setCheckReceivedObjects(true);
            rp.setCheckReferencedObjectsAreReachable(true);
            rp.setAdvertiseRefsHook(new HidePrivateHook());
            return rp;
          }
        };
    RemoteRefUpdate u =
        new RemoteRefUpdate( //
            src, //
            R_MASTER, // src name
            R_MASTER, // dst name
            false, // do not force update
            null, // local tracking branch
            null // expected id
            );
    PushResult r;
    try {
      t.setPushThin(true);
      r = t.push(PM, Collections.singleton(u));
    } finally {
      t.close();
    }

    assertNotNull("have result", r);
    assertNull("private not advertised", r.getAdvertisedRef(R_PRIVATE));
    assertSame("master updated", RemoteRefUpdate.Status.OK, u.getStatus());
    assertEquals(N, dst.resolve(R_MASTER));
  }
コード例 #26
0
 private TestRepository<InMemoryRepository>.CommitBuilder commit() {
   return git.commit();
 }