function slreqCCMergeSetup
% This function opens a cruise control project and makes a working copy in
% a local temp directory.

% prerequsits:
%  - git is installed
%  - comparisons.ExternalSCMLink.setupGitConfig() is executed

% Copyright 2021 The MathWorks, Inc.

    projectFolder = matlab.internal.project.example.projectDemoSetUp(...
        fullfile(matlabroot,'toolbox','slrequirements','slrequirementsdemos',...
        'CruiseRequirementsExample.zip'),[],'git');

    proj = openProject(projectFolder);
    proj.refreshSourceControl();
    reload(proj);

    branch1 = 'User1Feature';
    branch2 = 'User2Feature';

    system(['git branch ' branch1]);
    system(['git branch ' branch2]);

    % add non-conflicting changes - modify different requirements & links
    changeInBranch(branch1, '1', '1');
    changeInBranch(branch2, '2', '3');

end

function changeInBranch(branch, reqId, linkId)
    reqSetFile = 'crs_req_func_spec.slreqx';
    reqSetPath = fullfile('documents', reqSetFile);
    linkSetile = 'crs_controller.slmx';
    linkSetPath = fullfile('models', linkSetile);

    system(['git checkout ' branch]);
    msg = ['Updated in branch ' branch];

    reqSetObj = slreq.load(reqSetFile);
    reqObj = slreq.find('Type','Requirement','Id',reqId);
    reqObj.Rationale = msg;
    reqSetObj.save();

    linkSetObj = slreq.load(linkSetile);
    linkObj = linkSetObj.find('SID', linkId);
    linkObj.Rationale = msg;
    linkSetObj.save();

    slreq.clear();
    system(['git add ' reqSetPath]);
    system(['git add ' linkSetPath]);
    system('git add .' );
    system(['git commit -m "' msg '"']);
end
