Commit { void apply() throws ConflictException, DocumentStoreException { boolean success = false; RevisionVector baseRev = getBaseRevision(); boolean isBranch = baseRev != null && baseRev.isBranch(); Revision rev = getRevision(); if (isBranch && !nodeStore.isDisableBranches()) { try { prepare(baseRev); success = true; } finally { if (!success) { rollback(); Branch branch = getBranch(); if (branch != null) { branch.removeCommit(rev.asBranchRevision()); if (!branch.hasCommits()) { nodeStore.getBranches().remove(branch); } } } } } else { applyInternal(); } } Commit(@NotNull DocumentNodeStore nodeStore,
           @NotNull Revision revision,
           @Nullable RevisionVector baseRevision,
           @NotNull RevisionVector startRevisions);   Commit(@NotNull DocumentNodeStore nodeStore,
           @NotNull Revision revision,
           @Nullable RevisionVector baseRevision,
           @NotNull RevisionVector startRevisions,
           @NotNull Map<Path, UpdateOp> operations,
           @NotNull Set<Path> addedNodes,
           @NotNull Set<Path> removedNodes,
           @NotNull Set<Path> nodesWithBinaries,
           @NotNull Map<Path, Path> bundledNodes); void applyToCache(RevisionVector before, boolean isBranchCommit);  }
@Test public void mergeExceptionMessage() throws Exception { DocumentNodeStore ns = builderProvider.newBuilder().getNodeStore(); NodeBuilder b = ns.getRoot().builder(); b.child("foo"); ns.merge(b, EmptyHook.INSTANCE, CommitInfo.EMPTY); b = ns.getRoot().builder(); b.child("bar"); ns.merge(b, EmptyHook.INSTANCE, CommitInfo.EMPTY); Commit c = ns.newCommit(changes -> { changes.addNode(Path.fromString("/foo")); }, ns.getHeadRevision(), null); try { c.apply(); ns.done(c, false, CommitInfo.EMPTY); fail("commit must fail"); } catch (ConflictException e) { assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().contains("older than base")); } finally { ns.canceled(c); } }
@Test public void branchCommitFails() throws Exception { DocumentNodeStore ns = builderProvider.newBuilder().getNodeStore(); Commit c = ns.newCommit(changes -> { changes.removeNode(Path.fromString("/foo"), EMPTY_NODE); }, ns.getHeadRevision().asBranchRevision(ns.getClusterId()), null); try { try { c.apply(); fail("commit must fail"); } catch (ConflictException e) { assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().contains("does not exist")); } } finally { ns.canceled(c); } }
@Test public void alreadyDeletedMessage() throws Exception { DocumentNodeStore ns = builderProvider.newBuilder().getNodeStore(); NodeBuilder builder = ns.getRoot().builder(); builder.child("foo"); merge(ns, builder); builder = ns.getRoot().builder(); builder.child("foo").remove(); merge(ns, builder); Commit c = ns.newCommit(changes -> { changes.removeNode(Path.fromString("/foo"), EMPTY_NODE); }, ns.getHeadRevision().asBranchRevision(ns.getClusterId()), null); try { try { c.apply(); fail("commit must fail"); } catch (ConflictException e) { assertThat(e.getMessage(), containsString("base revision")); assertThat(e.getMessage(), containsString("branch")); } } finally { ns.canceled(c); } }