<commit_before>from jirafs import utils
from jirafs.plugin import CommandPlugin


class Command(CommandPlugin):
    """ Merge remote changes into your local copy """
    RUN_FOR_SUBTASKS = True
    TRY_SUBFOLDERS = True
    MIN_VERSION = '1.0a1'
    MAX_VERSION = '1.99.99'

    def handle(self, folder, **kwargs):
        return self.merge(folder)

    def merge(self, folder):
        with utils.stash_local_changes(folder):
            original_merge_base = folder.git_merge_base
            folder.run_git_command('merge', 'jira')
            final_merge_base = folder.git_merge_base

            if original_merge_base != final_merge_base:
                folder.log(
                    "Merged 'jira' into 'master'; merge-base is now %s" % (
                        final_merge_base
                    )
                )
            return utils.PostStatusResponse(
                original_merge_base == final_merge_base,
                final_merge_base
            )
<commit_msg>Report which fields and links are changed (and how) when merging.  Fixes #20.<commit_after>from jirafs import utils
from jirafs.plugin import CommandPlugin
from jirafs.jirafieldmanager import JiraFieldManager
from jirafs.jiralinkmanager import JiraLinkManager


class Command(CommandPlugin):
    """ Merge remote changes into your local copy """
    RUN_FOR_SUBTASKS = True
    TRY_SUBFOLDERS = True
    MIN_VERSION = '1.0a1'
    MAX_VERSION = '1.99.99'

    def handle(self, folder, **kwargs):
        return self.merge(folder)

    def merge(self, folder):
        with utils.stash_local_changes(folder):
            original_merge_base = folder.git_merge_base
            folder.run_git_command('merge', 'jira')
            final_merge_base = folder.git_merge_base

            jira_fields = JiraFieldManager.create(
                folder, revision='jira'
            )
            master_fields = JiraFieldManager.create(
                folder, revision=original_merge_base
            )
            for field, values in (jira_fields - master_fields).items():
                folder.log(
                    "Field {field} changed: \"{fr}\" -> \"{to}\"".format(
                        field=field,
                        fr=values[0],
                        to=values[1]
                    )
                )

            jira_links = JiraLinkManager.create(
                folder, revision='jira'
            )
            master_links = JiraLinkManager.create(
                folder, revision=original_merge_base
            )
            for category in ('issue', 'remote'):
                values_dict = (jira_links - master_links).get(category, {})
                for field, values in values_dict.items():
                    folder.log(
                        "Link {field} changed: \"{fr}\" -> \"{to}\"".format(
                            field=field,
                            fr=values[0],
                            to=values[1]
                        )
                    )

            if original_merge_base != final_merge_base:
                folder.log(
                    "Merged 'jira' into 'master'; merge-base is now %s" % (
                        final_merge_base
                    )
                )
            return utils.PostStatusResponse(
                original_merge_base == final_merge_base,
                final_merge_base
            )

{'fraction_non_alphanumeric': 0.08559622195985832, 'fraction_numerical': 0.006493506493506494, 'mean_word_length': 1.5558069381598794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7357287', 'n_tokens_mistral': 940, 'n_tokens_neox': 897, 'n_words': 193}