Example #1
0
  private GitilesView getView(String pathAndQuery) throws ServletException, IOException {
    final AtomicReference<GitilesView> view = Atomics.newReference();
    HttpServlet testServlet =
        new HttpServlet() {
          @Override
          protected void doGet(HttpServletRequest req, HttpServletResponse res) {
            view.set(ViewFilter.getView(req));
          }
        };

    ViewFilter vf =
        new ViewFilter(
            new TestGitilesAccess(repo.getRepository()),
            TestGitilesUrls.URLS,
            new VisibilityCache(false));
    MetaFilter mf = new MetaFilter();

    for (Pattern p : ImmutableList.of(ROOT_REGEX, REPO_REGEX, REPO_PATH_REGEX)) {
      mf.serveRegex(p).through(vf).with(testServlet);
    }

    FakeHttpServletRequest req = newRequest(repo.getRepository());
    int q = pathAndQuery.indexOf('?');
    if (q > 0) {
      req.setPathInfo(pathAndQuery.substring(0, q));
      req.setQueryString(pathAndQuery.substring(q + 1));
    } else {
      req.setPathInfo(pathAndQuery);
    }
    new MetaServlet(mf) {}.service(req, new FakeHttpServletResponse());

    return view.get();
  }
Example #2
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");
  }
Example #3
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);
 }
Example #4
0
  public void testAmbiguousBranchAndTag() throws Exception {
    RevCommit branch = repo.branch("refs/heads/name").commit().create();
    RevCommit tag = repo.branch("refs/tags/name").commit().create();
    GitilesView view;

    view = getView("/repo/+show/name");
    assertEquals(Type.REVISION, view.getType());
    assertEquals("name", view.getRevision().getName());
    assertEquals(tag, view.getRevision().getId());
    assertNull(view.getTreePath());

    view = getView("/repo/+show/heads/name");
    assertEquals(Type.REVISION, view.getType());
    assertEquals("heads/name", view.getRevision().getName());
    assertEquals(branch, view.getRevision().getId());
    assertNull(view.getTreePath());

    view = getView("/repo/+show/refs/heads/name");
    assertEquals(Type.REVISION, view.getType());
    assertEquals("refs/heads/name", view.getRevision().getName());
    assertEquals(branch, view.getRevision().getId());
    assertNull(view.getTreePath());

    view = getView("/repo/+show/tags/name");
    assertEquals(Type.REVISION, view.getType());
    assertEquals("tags/name", view.getRevision().getName());
    assertEquals(tag, view.getRevision().getId());
    assertNull(view.getTreePath());

    view = getView("/repo/+show/refs/tags/name");
    assertEquals(Type.REVISION, view.getType());
    assertEquals("refs/tags/name", view.getRevision().getName());
    assertEquals(tag, view.getRevision().getId());
    assertNull(view.getTreePath());
  }
Example #5
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);
 }
Example #6
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);
 }
  @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());
  }
Example #8
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);
 }
Example #9
0
 @Before
 public void setUp() throws Exception {
   repo =
       new TestRepository<DfsRepository>(
           new InMemoryRepository(new DfsRepositoryDescription("test")));
   walk = new RevWalk(repo.getRepository());
   cache = new TimeCache();
   start = repo.getClock().getTime() / 1000;
 }
  @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);
    }
  }
  @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());
  }
  @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);
  }
  @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);
  }
 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();
 }
 private RevCommit writeCommit(String body, PersonIdent author) throws Exception {
   try (ObjectInserter ins = testRepo.getRepository().newObjectInserter()) {
     CommitBuilder cb = new CommitBuilder();
     cb.setAuthor(author);
     cb.setCommitter(new PersonIdent(serverIdent, author.getWhen()));
     cb.setTreeId(testRepo.tree());
     cb.setMessage(body);
     ObjectId id = ins.insert(cb);
     ins.flush();
     RevCommit commit = walk.parseCommit(id);
     walk.parseBody(commit);
     return commit;
   }
 }
  @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);
  }
Example #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);
 }
Example #18
0
  @Test
  public void testCollectionWithGarbage() throws Exception {
    RevCommit commit0 = commit().message("0").create();
    RevCommit commit1 = commit().message("1").parent(commit0).create();
    git.update("master", commit0);

    assertTrue("commit0 reachable", isReachable(repo, commit0));
    assertFalse("commit1 garbage", isReachable(repo, commit1));
    gcNoTtl();

    assertEquals(2, odb.getPacks().length);
    DfsPackFile gc = null;
    DfsPackFile garbage = null;
    for (DfsPackFile pack : odb.getPacks()) {
      DfsPackDescription d = pack.getPackDescription();
      if (d.getPackSource() == GC) {
        gc = pack;
      } else if (d.getPackSource() == UNREACHABLE_GARBAGE) {
        garbage = pack;
      } else {
        fail("unexpected " + d.getPackSource());
      }
    }

    assertNotNull("created GC pack", gc);
    assertTrue(isObjectInPack(commit0, gc));

    assertNotNull("created UNREACHABLE_GARBAGE pack", garbage);
    assertTrue(isObjectInPack(commit1, garbage));
  }
Example #19
0
 @Before
 public void setUp() throws IOException {
   DfsRepositoryDescription desc = new DfsRepositoryDescription("test");
   git = new TestRepository<>(new InMemoryRepository(desc));
   repo = git.getRepository();
   odb = repo.getObjectDatabase();
 }
Example #20
0
  public void testBranches() throws Exception {
    RevCommit master = repo.branch("refs/heads/master").commit().create();
    RevCommit stable = repo.branch("refs/heads/stable").commit().create();
    GitilesView view;

    view = getView("/repo/+show/master");
    assertEquals(Type.REVISION, view.getType());
    assertEquals("master", view.getRevision().getName());
    assertEquals(master, view.getRevision().getId());
    assertNull(view.getTreePath());

    view = getView("/repo/+show/heads/master");
    assertEquals(Type.REVISION, view.getType());
    assertEquals("heads/master", view.getRevision().getName());
    assertEquals(master, view.getRevision().getId());
    assertNull(view.getTreePath());

    view = getView("/repo/+show/refs/heads/master");
    assertEquals(Type.REVISION, view.getType());
    assertEquals("refs/heads/master", view.getRevision().getName());
    assertEquals(master, view.getRevision().getId());
    assertNull(view.getTreePath());

    view = getView("/repo/+show/stable");
    assertEquals(Type.REVISION, view.getType());
    assertEquals("stable", view.getRevision().getName());
    assertEquals(stable, view.getRevision().getId());
    assertNull(view.getTreePath());
  }
Example #21
0
  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());
  }
  private ServletContextHandler dumb(final String path) {
    final File srcGit = remoteRepository.getRepository().getDirectory();
    final URI base = srcGit.getParentFile().toURI();

    ServletContextHandler ctx = server.addContext(path);
    ctx.setResourceBase(base.toString());
    ctx.addServlet(DefaultServlet.class, "/");
    return ctx;
  }
Example #23
0
 public void testDiffAgainstEmptyCommit() throws Exception {
   RevCommit master = repo.branch("refs/heads/master").commit().create();
   GitilesView view = getView("/repo/+diff/master^!");
   assertEquals(Type.DIFF, view.getType());
   assertEquals("master", view.getRevision().getName());
   assertEquals(master, view.getRevision().getId());
   assertEquals(Revision.NULL, view.getOldRevision());
   assertEquals("", view.getTreePath());
 }
Example #24
0
  @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()));
  }
  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);
  }
  @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();
    }
  }
Example #27
0
 /**
  * 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;
 }
Example #28
0
  public void testMultipleSlashes() throws Exception {
    RevCommit master = repo.branch("refs/heads/master").commit().create();
    GitilesView view;

    assertEquals(Type.HOST_INDEX, getView("//").getType());
    assertEquals(Type.REPOSITORY_INDEX, getView("//repo").getType());
    assertEquals(Type.REPOSITORY_INDEX, getView("//repo//").getType());
    assertNull(getView("/repo/+//master"));
    assertNull(getView("/repo/+/refs//heads//master"));
    assertNull(getView("/repo/+//master//"));
    assertNull(getView("/repo/+//master/foo//bar"));
  }
  @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);
  }
  @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);
  }