from general import *

def has_objects_and_refs(path):
    '''Returns True if <path>/objects and <path>/refs both exist and
    (after resolving any symlinks) are directories; returns False
    otherwise.  The existence of this directory structure is a
    resonable sanity check on <path> being a git repository'''
    objects_path = os.path.join(path,"objects")
    refs_path = os.path.join(path,"refs")
    return exists_and_is_directory(objects_path) and exists_and_is_directory(refs_path)

def probable_non_bare_repository(path):
    git_directory_path = os.path.join(path,'.git')
    return has_objects_and_refs(git_directory_path)

def is_in_another_git_repository(relative_path):
    if not exists_and_is_directory(relative_path):
        raise Exception("{} was not a directory".format(relative_path))
    while True:
        parent = os.path.dirname(relative_path)
        if not parent:
            return False
        if probable_non_bare_repository(parent):
            return True
        relative_path = parent

@@ -1020,8 +1020,1327 @@
  parent%0A
+%0A# default parameter was: setup.get_directory_to_backup()%0Adef find_git_repositories(start_path):%0A    '''Use the find-git-repos command to return a list of all directories%0A    which are working trees with git repositories.  (In other words, this%0A    does not find bare repositories.)%0A%0A    This used to be done by find-git-repos, but that inexplicably missed%0A    some paths.  This version isn't quite good enough, because it doesn't%0A    pay attention to .gitignore files - FIXME when I have time.  Instead%0A    for the moment if finds all non-bare git repositories, even if they%0A    would have been ignored.'''%0A    new_start_path = re.sub(r'/*$', '/', start_path)%0A    git_directories = %5B%5D%0A    for root, dirs, files in os.walk(start_path):%0A        directories_to_prune = %5B%5D%0A        for i, potential_git_directory in enumerate(dirs):%0A            full_name = os.path.join(root, potential_git_directory)%0A            if probable_non_bare_repository(full_name):%0A                relative_name = re.sub('%5E' + re.escape(new_start_path),%0A                                       '',%0A                                       full_name)%0A                git_directories.append(relative_name)%0A                directories_to_prune.append(i)%0A        for i in reversed(directories_to_prune):%0A            del dirs%5Bi%5D%0A    return git_directories%0A

Add another version of find_git_repositories