code: func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
  	rc := resmap.ResMap{}
  	for ix, patch := range pt.patches {
  		id := patch.Id()
  		existing, found := rc[id]
  		if !found {
  			rc[id] = patch
  			continue
  		}
  
  		versionedObj, err := scheme.Scheme.New(toSchemaGvk(id.Gvk()))
  		if err != nil && !runtime.IsNotRegisteredError(err) {
  			return nil, err
  		}
  		var cd conflictDetector
  		if err != nil {
  			cd = newJMPConflictDetector(pt.rf)
  		} else {
  			cd, err = newSMPConflictDetector(versionedObj, pt.rf)
  			if err != nil {
  				return nil, err
  			}
  		}
  
  		conflict, err := cd.hasConflict(existing, patch)
  		if err != nil {
  			return nil, err
  		}
  		if conflict {
  			conflictingPatch, err := cd.findConflict(ix, pt.patches)
  			if err != nil {
  				return nil, err
  			}
  			return nil, fmt.Errorf(
  				"conflict between %#v and %#v",
  				conflictingPatch.Map(), patch.Map())
  		}
  		merged, err := cd.mergePatches(existing, patch)
  		if err != nil {
  			return nil, err
  		}
  		rc[id] = merged
  	}
  	return rc, nil
  }
docs: // mergePatches merge and index patches by Id.
  // It errors out if there is conflict between patches.