def test_create_resolution(issue_1: Issue, issue_2: Issue, monkeypatch, first_repo: git.Repo): handler = IssueHandler() issue_1_path = handler.get_issue_path(issue_1) issue_2_path = handler.get_issue_path(issue_2) issues = [issue_1, issue_2] os.chdir(first_repo.working_dir) monkeypatch.setattr("git_issue.git_manager.GitManager.get_choice_from_user", lambda x, y: True) monkeypatch.setattr("builtins.input", lambda x: 'Y') uuids = [UUIDTrack(issue_1.uuid, issue_1.id), UUIDTrack(issue_2.uuid, issue_2.id)] resolution = CreateResolutionTool(issues, Tracker(len(uuids), uuids)) resolution.resolve() GitManager().commit("-m", "merge conflict resolution") assert issue_1_path.exists() assert issue_2_path.exists() result_1 = handler.get_issue_from_issue_id(issues[0].id) result_2 = handler.get_issue_from_issue_id(issues[1].id) assert issues[0] == result_1 assert issues[1] == result_2
def resolve(self): gm = GitManager() gm.load_issue_branch() paths = [] handler = IssueHandler() for issue in self.resolved_issues: file_path = handler.get_issue_path(issue) JsonConvert.ToFile(issue, file_path) paths.append(str(file_path)) repo = gm.obtain_repo() for path in paths: repo.git.add(path)
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))