<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def clone(local_root, new_root, remote, branch, rel_dest, exclude):
 """Clone "local_root" origin into a new directory and check out a specific branch. Optionally run "git rm". :raise CalledProcessError: Unhandled git command failure. :raise GitError: Handled git failures. :param str local_root: Local path to git root directory. :param str new_root: Local path empty directory in which branch will be cloned into. :param str remote: The git remote to clone from to. :param str branch: Checkout this branch. :param str rel_dest: Run "git rm" on this directory if exclude is truthy. :param iter exclude: List of strings representing relative file paths to exclude from "git rm". """

    log = logging.getLogger(__name__)
    output = run_command(local_root, ['git', 'remote', '-v'])
    remotes = dict()
    for match in RE_ALL_REMOTES.findall(output):
        remotes.setdefault(match[0], [None, None])
        if match[2] == 'fetch':
            remotes[match[0]][0] = match[1]
        else:
            remotes[match[0]][1] = match[1]
    if not remotes:
        raise GitError('Git repo has no remotes.', output)
    if remote not in remotes:
        raise GitError('Git repo missing remote "{}".'.format(remote), output)

    # Clone.
    try:
        run_command(new_root, ['git', 'clone', remotes[remote][0], '--depth=1', '--branch', branch, '.'])
    except CalledProcessError as exc:
        raise GitError('Failed to clone from remote repo URL.', exc.output)

    # Make sure user didn't select a tag as their DEST_BRANCH.
    try:
        run_command(new_root, ['git', 'symbolic-ref', 'HEAD'])
    except CalledProcessError as exc:
        raise GitError('Specified branch is not a real branch.', exc.output)

    # Copy all remotes from original repo.
    for name, (fetch, push) in remotes.items():
        try:
            run_command(new_root, ['git', 'remote', 'set-url' if name == 'origin' else 'add', name, fetch], retry=3)
            run_command(new_root, ['git', 'remote', 'set-url', '--push', name, push], retry=3)
        except CalledProcessError as exc:
            raise GitError('Failed to set git remote URL.', exc.output)

    # Done if no exclude.
    if not exclude:
        return

    # Resolve exclude paths.
    exclude_joined = [
        os.path.relpath(p, new_root) for e in exclude for p in glob.glob(os.path.join(new_root, rel_dest, e))
    ]
    log.debug('Expanded %s to %s', repr(exclude), repr(exclude_joined))

    # Do "git rm".
    try:
        run_command(new_root, ['git', 'rm', '-rf', rel_dest])
    except CalledProcessError as exc:
        raise GitError('"git rm" failed to remove ' + rel_dest, exc.output)

    # Restore files in exclude.
    run_command(new_root, ['git', 'reset', 'HEAD'] + exclude_joined)
    run_command(new_root, ['git', 'checkout', '--'] + exclude_joined)