def test_divergence_resolver(issue_1, issue_2, issue_3, monkeypatch):
    resolved_issues = [issue_1, issue_2, issue_3]
    resolved_tracker = Tracker()

    summary_edit = "This edit resolves the create-edit-divergence"
    monkeypatch.setattr("builtins.input", lambda x: summary_edit)

    for issue in resolved_issues:
        resolved_tracker.track_or_update_uuid(issue.uuid, issue.id)

    issue_3_json = JsonConvert.ToJSON(issue_3)
    issue_3_copy = JsonConvert.FromJSON(issue_3_json)
    issue_3_copy.summary = "This is the edited field for the create-edit-divergence"
    issue_3_copy.id = issue_2.id

    expected = JsonConvert.FromJSON(issue_3_json)
    expected.summary = summary_edit

    resolver = DivergenceConflictResolver()
    resolver.resolved_tracker = resolved_tracker
    resolver.resolved_conflicts = resolved_issues
    resolver.diverged_issues = [(issue_3, issue_3_copy)]

    resolution = resolver.generate_resolution()
    assert [issue_3, expected] == resolution.resolved_issues
def test_filter_manual_conflicts(issue_1, issue_2, first_repo):
    create = ConflictInfo(None, [issue_1, issue_1, issue_2])

    issue_1_json = JsonConvert.ToJSON(issue_1)
    issue_1_copy = JsonConvert.FromJSON(issue_1_json)
    issue_1_copy.uuid = issue_2.uuid

    manual = ConflictInfo(None, [issue_1_copy, issue_1_copy, issue_1_copy])

    result = GitMerge(first_repo).filter_manual_conflicts([create, manual])
    assert [manual] == result
Example #3
0
    def parse_unmerged_conflicts(self) -> [ConflictInfo]:
        unmerged_blobs = self.repo.index.unmerged_blobs()
        unmerged: [ConflictInfo] = []

        for unmerged_file in unmerged_blobs:
            conflicts = []

            for (stage, blob) in unmerged_blobs[unmerged_file]:
                if stage != 0:
                    data = blob.data_stream.read().decode()
                    obj = JsonConvert.FromJSON(data)

                    conflicts.append(obj)

            unmerged.append(ConflictInfo(unmerged_file, conflicts))

        return unmerged
def test_produce_divergence_resolver(issue_1, issue_2, issue_3, first_repo):
    resolved_issues = [issue_1, issue_2, issue_3]
    resolved_tracker = Tracker()

    for issue in resolved_issues:
        resolved_tracker.track_or_update_uuid(issue.uuid, issue.id)

    issue_2_json = JsonConvert.ToJSON(issue_2)
    issue_2_copy = JsonConvert.FromJSON(issue_2_json)
    issue_2_copy.uuid = 53368803138698180295652887974160049016

    conflict = ConflictInfo(IssueHandler().get_issue_path(issue_2), [issue_2, issue_2, issue_2_copy])

    merger = GitMerge(first_repo)
    resolver = merger.produce_create_edit_divergence_resolver([conflict], resolved_issues, resolved_tracker)
    assert resolved_issues == resolver.resolved_conflicts and resolved_tracker == resolver.resolved_tracker
    assert [(issue_2, issue_2_copy)] == resolver.diverged_issues
def test_unmerged_conflicts(issue_1: Issue, issue_2: Issue, issue_3: Issue, first_repo: git.Repo, second_repo: git.Repo,
                            monkeypatch):
    # Create, Create-Edit-Divergence, Comment-Index, Manual
    issue_2_json = JsonConvert.ToJSON(issue_2)
    issue_2_copy = JsonConvert.FromJSON(issue_2_json)
    issue_2_copy.summary = "Edited Summary"

    monkeypatch.setattr("git_issue.git_manager.GitManager.get_choice_from_user", lambda x, y: True)
    monkeypatch.setattr("builtins.input", lambda x: 'Y')

    def merge(repo):
        try:
            repo.git.checkout("issue")
            repo.git.pull("--allow-unrelated-histories", "other", GitManager.ISSUE_BRANCH)
        except:
            pass

        merger = GitMerge(repo)
        return merger.parse_unmerged_conflicts()

    # Set up first repo for Create conflict
    os.chdir(first_repo.working_dir)
    handler = IssueHandler()
    handler.store_issue(issue_2, "test", generate_id=True)

    # Set up second repo for Create conflict
    os.chdir(second_repo.working_dir)
    handler = IssueHandler()
    handler.store_issue(issue_1, "test", generate_id=True)

    result = merge(second_repo)
    expected = [ConflictInfo("ISSUE-1/issue.json", [issue_1, issue_2])]
    assert expected == result
    GitSynchronizer().merge(GitMerge(second_repo))

    # Set up first repo for divergence conflict
    os.chdir(first_repo.working_dir)
    handler = IssueHandler()
    issue_2_copy.id = issue_1.id
    handler.store_issue(issue_2_copy, "test")

    os.chdir(second_repo.working_dir)
    result = merge(second_repo)
    expected = [ConflictInfo("ISSUE-1/issue.json", [issue_2, issue_1, issue_2_copy])]
    assert expected == result
    GitSynchronizer().merge(GitMerge(second_repo))


    # Comment
    os.chdir(first_repo.working_dir)
    handler = IssueHandler()
    comment_handler = CommentHandler(handler.get_issue_path(issue_1), issue_1.id)
    first_comment = Comment("first repo")
    first_entry = comment_handler.add_comment(first_comment)

    # Comment
    os.chdir(second_repo.working_dir)
    handler = IssueHandler()
    comment_handler = CommentHandler(handler.get_issue_path(issue_1), issue_1.id)
    second_comment = Comment("second repo")
    second_entry = comment_handler.add_comment(second_comment)

    result = merge(second_repo)
    expected = [ConflictInfo("ISSUE-1/index.json", [Index([second_entry]), Index([first_entry])])]

    assert expected == result
    GitSynchronizer().merge(GitMerge(second_repo))

    # Edit conflict
    issue_1.id = "ISSUE-10" # Just so we don't need to work out the ID
    issue_1_json = JsonConvert.ToJSON(issue_1)
    issue_1_first_repo = JsonConvert.FromJSON(issue_1_json)
    issue_1_second_repo = JsonConvert.FromJSON(issue_1_json)
    issue_1_first_repo.summary = "First Repo"
    issue_1_second_repo.summary = "Second Repo"

    # Set up both repos with the issue that will be used as a conflict
    os.chdir(first_repo.working_dir)
    handler = IssueHandler()
    handler.store_issue(issue_1, "test")
    os.chdir(second_repo.working_dir)
    result = merge(second_repo)

    # Edit first repo
    os.chdir(first_repo.working_dir)
    handler.store_issue(issue_1_first_repo, "test")

    # Edit second repo
    os.chdir(second_repo.working_dir)
    handler = IssueHandler()
    handler.store_issue(issue_1_second_repo, "issue 10 edit")
    result = merge(second_repo)

    expected = [ConflictInfo("ISSUE-10/issue.json", [issue_1, issue_1_second_repo, issue_1_first_repo])]
    assert expected == result
    GitSynchronizer().merge(GitMerge(second_repo))