Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    def pull(self, merge_on_failure=False):
        try:
            print("Pulling from remote branch.")
            self.repo.git.pull()
            print("Successfully pulled from remote branch.")
        except GitCommandError as e:
            merger = GitMerge(self.repo)

            if merge_on_failure and merger.has_conflicts():
                self.merge(merger)
            else:
                print(
                    "Failed to pull from remote issue branch. Refer to the error below for more details:"
                )
                print(e.stderr)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def test_produce_create_resolver(issue_1: Issue, issue_2: Issue, first_repo):
    conflict = ConflictInfo("fake_path", [issue_1, issue_2])

    # Not what we're testing in this unit, but it's imperative that we know
    # what we're dealing with is a create conflict
    assert conflict.type == ConflictType.CREATE

    merger = GitMerge(first_repo)
    tracks = [UUIDTrack(issue.uuid, issue.id) for issue in conflict.conflicts]
    result = merger.produce_create_resolver([conflict,
                                             ConflictInfo("Another fake path", [Tracker(len(tracks), tracks)])])

    assert 1 == len(result.conflicts) and 2 == len(result.conflicts[0].conflicts)
    assert 2 == len(result.tracker.tracked_uuids) and 2 == result.tracker.issue_count

    assert conflict == result.conflicts[0]
    assert tracks == result.tracker.tracked_uuids
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
 def action():
     sync = GitSynchronizer()
     sync.merge(GitMerge(sync.repo))
     sync = None
Ejemplo n.º 7
0
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))
Ejemplo n.º 8
0
def test_produce_comment_index_resolver(comment_index_conflict, first_repo):
    merger = GitMerge(first_repo)
    resolver = merger.produce_comment_index_resolvers([comment_index_conflict])
    assert len(resolver) == 1 and comment_index_conflict == resolver[0].conflict_info