Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java (revision 1436785) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java (working copy) @@ -168,7 +168,11 @@ private void prepareCommit() throws Exception { commit.setAffectedPaths(affectedPaths); - commit.setBaseRevisionId(mongoSync.getHeadRevisionId()); + if (branchId == null) { + commit.setBaseRevisionId(mongoSync.getHeadRevisionId()); + } else { + commit.setBaseRevisionId(baseRevisionId); + } commit.setRevisionId(revisionId); if (commit.getBranchId() == null && branchId != null) { commit.setBranchId(branchId); @@ -191,9 +195,13 @@ existingNodes = new HashMap(); for (String path : affectedPaths) { - NodeExistsCommand command = new NodeExistsCommand( - nodeStore, path, mongoSync.getHeadRevisionId()); - command.setBranchId(branchId); + NodeExistsCommand command; + if (branchId == null) { + command = new NodeExistsCommand(nodeStore, path, mongoSync.getHeadRevisionId()); + } else { + command = new NodeExistsCommand(nodeStore, path, baseRevisionId); + command.setBranchId(branchId); + } if (command.execute()) { existingNodes.put(path, command.getNode()); } @@ -297,6 +305,11 @@ * @throws Exception If an exception happens. */ protected boolean saveAndSetHeadRevision() throws Exception { + // Don't update the head revision id for branches. + if (branchId != null) { + return true; + } + long assumedHeadRevision = this.mongoSync.getHeadRevisionId(); MongoSync mongoSync = new SaveAndSetHeadRevisionAction(nodeStore, assumedHeadRevision, revisionId).execute();