Index: src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java =================================================================== --- src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java (revision 1436250) +++ src/main/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandNew.java (working copy) @@ -161,7 +161,7 @@ private void prepareCommit() throws Exception { commit.setAffectedPaths(new LinkedList(affectedPaths)); - commit.setBaseRevisionId(mongoSync.getHeadRevisionId()); + commit.setBaseRevisionId(baseRevisionId); commit.setRevisionId(revisionId); if (commit.getBranchId() == null && branchId != null) { commit.setBranchId(branchId); @@ -184,9 +184,14 @@ 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()); } @@ -290,6 +295,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();