<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def harvest_repo(root_url, archive_path, tag=None, archive_format='tar.gz'):
 """ Archives a specific tag in a specific Git repository. :param root_url: The URL to the Git repo - Supported protocols: git, ssh, http[s]. :param archive_path: A temporary path to clone the repo to - Must end in .git :param tag: The path to which the .tar.gz will go to - Must end in the same as format (NOT inside clone_path) :param format: One of the following: tar.gz / tar / zip """


    if not git_exists():
        raise Exception("Git not found. It probably needs installing.")

    clone_path = mkdtemp(dir=cfg['CFG_TMPDIR'])

    git = get_which_git()

    call([git, 'clone', root_url, clone_path])
    chdir(clone_path)

    if tag:
        call([git, 'archive', '--format=' + archive_format, '-o',
              archive_path, tag])
    else:
        call([git, 'archive', '--format=' + archive_format, '-o',
              archive_path, 'HEAD'])

    try:
        rmtree(clone_path)
    except OSError as e:
        # Reraise unless ENOENT: No such file or directory
        # (ok if directory has already been deleted)
        if e.errno != errno.ENOENT:
            raise