Main Content

Determine Order for Resolving Conflicts Using Dependency Analyzer

When collaborating on a project, a branch merge can lead to conflicted files. For a smoother merge, you can determine the optimal order in which to resolve conflicts by running a dependency analysis. Conflicts in files that are used by other files should be resolved first. Conflicts in files that do not have dependencies do not affect other files, so the conflict resolve order does not matter.

Note

If the project dependency graph contains circular dependencies, there might not be an optimal order in which to resolve conflicts.

You can use the Dependency Analyzer to programmatically determine the optimal order in which to resolve conflicts. In the MATLAB® Command Window, run the getProjectResolveOrder function.

function fileOrder = getProjectResolveOrder()
    import matlab.sourcecontrol.Status;
    p = currentProject;
    conflictingFiles = p.Files([p.Files.SourceControlStatus] == Status.Conflicted);
    updateDependencies(p);
    graph = p.Dependencies;
    
    if ~isdag(graph)
        error("Unable to recommend an optimal resolve order. The dependency graph contains circular dependencies.")
    end
    
    topologicalOrder = toposort(graph);
    topologicalFiles = graph.Nodes.Name(topologicalOrder);
    fileIndices = ismember(topologicalFiles, [conflictingFiles.Path]);
    files = flip(topologicalFiles(fileIndices));
    nodependencyFiles = setdiff(cellstr([conflictingFiles.Path])',files);
    fileOrder = [files;nodependencyFiles];
end
getProjectResolveOrder

ans =

  6×1 cell array

    {'C:\workSpace\examples\airframe\src\timesthree.c'            }
    {'C:\workSpace\examples\airframe\lib\timesthree.tlc'          }
    {'C:\workSpace\examples\airframe\models\NonLinearActuator.slx'}
    {'C:\workSpace\examples\airframe\models\f14_airframe.slx'     }
    {'C:\workSpace\examples\airframe\models\slproject_f14.slx'    }
    {'C:\workSpace\examples\airframe\tests\f14_airframe_test.m'   }

Resolve conflicts according to the listed order. For more details, see Resolve Conflicts.

Related Topics