protected UpdateScmResult executeUpdateCommand()

in maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/update/HgUpdateCommand.java [52:106]


    protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion tag)
            throws ScmException {
        File workingDir = fileSet.getBasedir();

        String[] updateCmd;
        // Update branch
        if (repo.isPushChanges()) {
            updateCmd = new String[] {
                HgCommandConstants.PULL_CMD,
                HgCommandConstants.REVISION_OPTION,
                tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip"
            };
        } else {
            updateCmd = new String[] {
                HgCommandConstants.UPDATE_CMD,
                tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip",
                HgCommandConstants.CLEAN_OPTION
            };
        }
        ScmResult updateResult = HgUtils.execute(new HgConsumer(), workingDir, updateCmd);

        if (!updateResult.isSuccess()) {
            return new UpdateScmResult(null, null, updateResult);
        }

        // Find changes from last revision
        int currentRevision = HgUtils.getCurrentRevisionNumber(workingDir);
        int previousRevision = currentRevision - 1;
        String[] diffCmd =
                new String[] {HgCommandConstants.DIFF_CMD, HgCommandConstants.REVISION_OPTION, "" + previousRevision};
        HgDiffConsumer diffConsumer = new HgDiffConsumer(workingDir);
        ScmResult diffResult = HgUtils.execute(diffConsumer, workingDir, diffCmd);

        // Now translate between diff and update file status
        List<ScmFile> updatedFiles = new ArrayList<>();
        List<CharSequence> changes = new ArrayList<>();
        List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
        Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
        for (ScmFile file : diffFiles) {
            changes.add(diffChanges.get(file.getPath()));
            if (file.getStatus() == ScmFileStatus.MODIFIED) {
                updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
            } else {
                updatedFiles.add(file);
            }
        }

        if (repo.isPushChanges()) {
            String[] hgUpdateCmd = new String[] {HgCommandConstants.UPDATE_CMD};
            HgUtils.execute(new HgConsumer(), workingDir, hgUpdateCmd);
        }

        return new UpdateScmResultWithRevision(
                updatedFiles, new ArrayList<>(0), String.valueOf(currentRevision), diffResult);
    }