def METHOD_NAME(isolation, path, branch_name, delete, new_branch, merge_args=("--ff-only",), exception=None):
    """Cleanup and merge a previously created Git worktree."""
    exc_info: Tuple[Optional[Type[Any]], Any, Any] = (None, None, None)
    if exception:
        exc_info = (type(exception), exception, exception.__traceback__)
    isolation.__exit__(*exc_info)
    project_context.pop_context()
    repository = project_context.repository
    try:
        repository.run_git_command("merge", branch_name, *merge_args)
    except errors.GitCommandError:
        raise errors.FailedMerge(repository, branch_name, merge_args)
    if delete:
        repository.remove_worktree(path)
        if new_branch:
            # delete the created temporary branch
            repository.branches.remove(branch_name)
    if project_context.external_storage_requested:
        checkout_paths_from_storage()