alex / pyvcs

A pure python abstraction layer of multiple VCS, very lightweight.
BSD 3-Clause "New" or "Revised" License
127 stars 10 forks source link

Mercurial backend fails to raise FolderDoesNotExist when appropriate #4

Closed stucchio closed 15 years ago

stucchio commented 15 years ago

The list_directory(path) method in the hg backend should raise a FolderDoesNotExist exception if the folder doesn't actually exist. Currently, it returns [[], []]. An easy fix:

def list_directory(self, path, revision=None):
    """
    Returns a list of files in a directory (list of strings) at a given
    revision, or HEAD if revision is None.
    """
    chgctx = self.repo.changectx(revision)
    file_list = []
    folder_list = []
    found_path = False #Make sure we find path somewhere in the manifest.
    for file, node in chgctx.manifest().items():
        if not file.startswith(path):
            continue
        found_path = True #If we find anything in the manifest under this path, then this folder must exist.
        folder_name = '/'.join(file.lstrip(path).split('/')[:-1])
        if folder_name != '':
            if folder_name not in folder_list:
                folder_list.append(folder_name)
        if '/' not in file.lstrip(path):
            file_list.append(file)
    if not found_path: #If we never found the path within the manifest, it does not exist.
        raise FolderDoesNotExist
    return file_list, folder_list
alex commented 15 years ago

Fixed in the same patch as #3, thanks for your help Chris!