code: protected void doMerge(NodeData mergeNode) throws RepositoryException
     {
        // let n' be the corresponding node of n in ws'.
        // find corr node for this node
        NodeData corrNode = getCorrNodeData(mergeNode);
        if (corrNode != null)
        {
  
           NodeData mergeVersion = getBaseVersionData(mergeNode, mergeSession);
  
           if (mergeVersion != null)
           {
  
              NodeData corrVersion = getBaseVersionData(corrNode, corrSession);
  
              if (corrVersion != null)
              {
                 // let v be base version of n.
                 // let v' be base version of n'.
  
                 SessionDataManager mergeDataManager = mergeSession.getTransientNodesManager();
  
                 PropertyData isCheckedOutProperty =
                    (PropertyData)mergeDataManager.getItemData(mergeNode, new QPathEntry(Constants.JCR_ISCHECKEDOUT, 0),
                       ItemType.PROPERTY);
  
                 if (!ValueDataUtil.getBoolean(isCheckedOutProperty.getValues().get(0))
                    && isSuccessor(mergeVersion, corrVersion))
                 {
                    // if v' is a successor of v and
                    // n is not checked-in doupdate(n, n').
                    doUpdate(mergeNode, corrNode);
                 }
                 else if (mergeVersion.getQPath().equals(corrVersion.getQPath())
                    || isPredecessor(mergeVersion, corrVersion))
                 {
                    // else if v is equal to or a predecessor of v' doleave(n).
                    doLeave(mergeNode);
                 }
                 else
                 {
                    // else dofail(n, v').
                    doFail(mergeNode, corrVersion);
                 }
              }
              else
              {
                 // else if n' is not versionable doleave(n)
                 doLeave(mergeNode);
              }
           }
           else
           {
              // else if n is not versionable doupdate(n, n')
              doUpdate(mergeNode, corrNode);
           }
        }
        else
        {
           // if no such n' doleave(n).
           doLeave(mergeNode);
        }
     }
docs: -------------------- merge actions ------------