| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6eb3af2 commit e859042
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,10 @@ class InvalidGitRepositoryError(Exception): | |||
| 14 | 14 | """ Thrown if the given repository appears to have an invalid format. """ | |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | + class WorkTreeRepositoryUnsupported(InvalidGitRepositoryError): | ||
| 18 | + """ Thrown to indicate we can't handle work tree repositories """ | ||
| 19 | + | ||
| 20 | + | ||
| 17 | 21 | class NoSuchPathError(OSError): | |
| 18 | 22 | """ Thrown if a path could not be access by the system. """ | |
| 19 | 23 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | from gitdb.exc import ( | |
| 6 | 6 | BadObject, | |
| 7 | - BadName | ||
| 7 | + BadName, | ||
| 8 | 8 | ) | |
| 9 | 9 | from git.refs import SymbolicReference | |
| 10 | 10 | from git.objects import Object | |
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | hex_to_bin, | |
| 17 | 17 | bin_to_hex | |
| 18 | 18 | ) | |
| 19 | + from git.exc import WorkTreeRepositoryUnsupported | ||
| 19 | 20 | from git.compat import xrange | |
| 20 | 21 | ||
| 21 | 22 | ||
@@ -31,14 +32,20 @@ def touch(filename): | |||
| 31 | 32 | ||
| 32 | 33 | def is_git_dir(d): | |
| 33 | 34 | """ This is taken from the git setup.c:is_git_directory | |
| 34 | - function.""" | ||
| 35 | - if isdir(d) and \ | ||
| 36 | - isdir(join(d, 'objects')) and \ | ||
| 37 | - isdir(join(d, 'refs')): | ||
| 38 | - headref = join(d, 'HEAD') | ||
| 39 | - return isfile(headref) or \ | ||
| 40 | - (os.path.islink(headref) and | ||
| 41 | - os.readlink(headref).startswith('refs')) | ||
| 35 | + function. | ||
| 36 | + | ||
| 37 | + @throws WorkTreeRepositoryUnsupported if it sees a worktree directory. It's quite hacky to do that here, | ||
| 38 | + but at least clearly indicates that we don't support it. | ||
| 39 | + There is the unlikely danger to throw if we see directories which just look like a worktree dir, | ||
| 40 | + but are none.""" | ||
| 41 | + if isdir(d): | ||
| 42 | + if isdir(join(d, 'objects')) and isdir(join(d, 'refs')): | ||
| 43 | + headref = join(d, 'HEAD') | ||
| 44 | + return isfile(headref) or \ | ||
| 45 | + (os.path.islink(headref) and | ||
| 46 | + os.readlink(headref).startswith('refs')) | ||
| 47 | + elif isfile(join(d, 'gitdir')) and isfile(join(d, 'commondir')) and isfile(join(d, 'gitfile')): | ||
| 48 | + raise WorkTreeRepositoryUnsupported(d) | ||
| 42 | 49 | return False | |
| 43 | 50 | ||
| 44 | 51 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,7 +33,10 @@ | |||
| 33 | 33 | ) | |
| 34 | 34 | from git.repo.fun import touch | |
| 35 | 35 | from git.util import join_path_native | |
| 36 | - from git.exc import BadObject | ||
| 36 | + from git.exc import ( | ||
| 37 | + BadObject, | ||
| 38 | + WorkTreeRepositoryUnsupported | ||
| 39 | + ) | ||
| 37 | 40 | from gitdb.util import bin_to_hex | |
| 38 | 41 | from git.compat import string_types | |
| 39 | 42 | from gitdb.test.lib import with_rw_directory | |
@@ -45,6 +48,8 @@ | |||
| 45 | 48 | import itertools | |
| 46 | 49 | from io import BytesIO | |
| 47 | 50 | ||
| 51 | + from nose import SkipTest | ||
| 52 | + | ||
| 48 | 53 | ||
| 49 | 54 | class TestRepo(TestBase): | |
| 50 | 55 | ||
@@ -779,3 +784,16 @@ def test_is_ancestor(self): | |||
| 779 | 784 | self.assertFalse(repo.is_ancestor("master", c1)) | |
| 780 | 785 | for i, j in itertools.permutations([c1, 'ffffff', ''], r=2): | |
| 781 | 786 | self.assertRaises(GitCommandError, repo.is_ancestor, i, j) | |
| 787 | + | ||
| 788 | + @with_rw_directory | ||
| 789 | + def test_work_tree_unsupported(self, rw_dir): | ||
| 790 | + git = Git(rw_dir) | ||
| 791 | + if git.version_info[:3] < (2, 5, 1): | ||
| 792 | + raise SkipTest("worktree feature unsupported") | ||
| 793 | + | ||
| 794 | + rw_master = self.rorepo.clone(join_path_native(rw_dir, 'master_repo')) | ||
| 795 | + rw_master.git.checkout('HEAD~10') | ||
| 796 | + worktree_path = join_path_native(rw_dir, 'worktree_repo') | ||
| 797 | + rw_master.git.worktree('add', worktree_path, 'master') | ||
| 798 | + | ||
| 799 | + self.failUnlessRaises(WorkTreeRepositoryUnsupported, Repo, worktree_path) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments