def _git_rel_path(path): try: repo = Repo(path, search_parent_directories=True) index = IndexFile(repo) path = Path(index._to_relative_path(path)) return path.as_posix() except Exception: return ''
def test__to_relative_path_at_root(self): root = osp.abspath(os.sep) class Mocked(object): bare = False git_dir = root working_tree_dir = root repo = Mocked() path = os.path.join(root, 'file') index = IndexFile(repo) rel = index._to_relative_path(path) self.assertEqual(rel, os.path.relpath(path, root))