def test_rename_add_merge(smart_repo: SmartRepo): added_line_path = CursorPath( ('a.c', 'main()', (CursorKind.COMPOUND_STMT, 0), (CursorKind.COMPOUND_ASSIGNMENT_OPERATOR, 0))) variable_path = CursorPath(('a.c', 'main()', (CursorKind.COMPOUND_STMT, 0), (CursorKind.DECL_STMT, 0), 'a')) file_added = FileAdded('a.c', smart_repo.contents('a.c', 'initial')) line_added = SubASTInserted(smart_repo, smart_repo.contents('a.c', 'add-line'), added_line_path) renamed = VariableRenamed(variable_path, 'b') final_contents = as_lines('', 'int main() {', ' int b = 0;', ' b += 1;', ' return b;', '}') assert get_changes(smart_repo, 'other-to-master') \ == [[file_added], [renamed], [SubASTInserted(smart_repo, final_contents, added_line_path)]] assert tuple(smart_repo.rev_parse('other-to-master').parents) == ( smart_repo.rev_parse('rename'), smart_repo.rev_parse('add-line')) assert get_changes(smart_repo, 'master-to-other') \ == [[file_added], [line_added], [renamed]] assert tuple(smart_repo.rev_parse('master-to-other').parents) == ( smart_repo.rev_parse('add-line'), smart_repo.rev_parse('rename')) assert smart_repo.contents('a.c', 'other-to-master')\ == smart_repo.contents('a.c', 'master-to-other') \ == final_contents
def get_changes(repo: SmartRepo, revision: str='HEAD') -> List[List[Change]]: changes_file_contents = repo.contents(CHANGES_FILE_NAME, revision) if changes_file_contents is None: return [] return decode_changes(repo, changes_file_contents)
def test_detect(smart_repo: SmartRepo): a = smart_repo.find_cursor('a.c', lambda c: c.spelling == 'b').drop(1).appended('a') assert get_changes(smart_repo) == [[FileAdded('a.c', smart_repo.contents('a.c', 'initial'))], [VariableRenamed(a, 'b')]]