コード例 #1
0
 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 ''
コード例 #2
0
ファイル: test_index.py プロジェクト: klausstocking/GitPython
    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))
コード例 #3
0
    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))