Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite859042

Browse files
committed
fix(repo): fail loudly if worktrees are used
As GitPython is in maintenance mode, there will be no new features.However, I believe it's good idea to explicitly state we do not supportcertain things if this is the case.Therefore, when worktrees are encountered, we will throw an specificexception to indicate that.The current implementation is hacky to speed up development,and increases the risk of failing due to false-positive worktreedirectories.Related to#344
1 parent6eb3af2 commite859042

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

‎git/exc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class InvalidGitRepositoryError(Exception):
1414
""" Thrown if the given repository appears to have an invalid format. """
1515

1616

17+
classWorkTreeRepositoryUnsupported(InvalidGitRepositoryError):
18+
""" Thrown to indicate we can't handle work tree repositories """
19+
20+
1721
classNoSuchPathError(OSError):
1822
""" Thrown if a path could not be access by the system. """
1923

‎git/repo/fun.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
fromgitdb.excimport (
66
BadObject,
7-
BadName
7+
BadName,
88
)
99
fromgit.refsimportSymbolicReference
1010
fromgit.objectsimportObject
@@ -16,6 +16,7 @@
1616
hex_to_bin,
1717
bin_to_hex
1818
)
19+
fromgit.excimportWorkTreeRepositoryUnsupported
1920
fromgit.compatimportxrange
2021

2122

@@ -31,14 +32,20 @@ def touch(filename):
3132

3233
defis_git_dir(d):
3334
""" This is taken from the git setup.c:is_git_directory
34-
function."""
35-
ifisdir(d)and \
36-
isdir(join(d,'objects'))and \
37-
isdir(join(d,'refs')):
38-
headref=join(d,'HEAD')
39-
returnisfile(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+
ifisdir(d):
42+
ifisdir(join(d,'objects'))andisdir(join(d,'refs')):
43+
headref=join(d,'HEAD')
44+
returnisfile(headref)or \
45+
(os.path.islink(headref)and
46+
os.readlink(headref).startswith('refs'))
47+
elifisfile(join(d,'gitdir'))andisfile(join(d,'commondir'))andisfile(join(d,'gitfile')):
48+
raiseWorkTreeRepositoryUnsupported(d)
4249
returnFalse
4350

4451

‎git/test/test_repo.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
)
3434
fromgit.repo.funimporttouch
3535
fromgit.utilimportjoin_path_native
36-
fromgit.excimportBadObject
36+
fromgit.excimport (
37+
BadObject,
38+
WorkTreeRepositoryUnsupported
39+
)
3740
fromgitdb.utilimportbin_to_hex
3841
fromgit.compatimportstring_types
3942
fromgitdb.test.libimportwith_rw_directory
@@ -45,6 +48,8 @@
4548
importitertools
4649
fromioimportBytesIO
4750

51+
fromnoseimportSkipTest
52+
4853

4954
classTestRepo(TestBase):
5055

@@ -779,3 +784,16 @@ def test_is_ancestor(self):
779784
self.assertFalse(repo.is_ancestor("master",c1))
780785
fori,jinitertools.permutations([c1,'ffffff',''],r=2):
781786
self.assertRaises(GitCommandError,repo.is_ancestor,i,j)
787+
788+
@with_rw_directory
789+
deftest_work_tree_unsupported(self,rw_dir):
790+
git=Git(rw_dir)
791+
ifgit.version_info[:3]< (2,5,1):
792+
raiseSkipTest("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)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp