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

Commit96c6ab4

Browse files
committed
Added search_parent_directories keyword argument to Repo type.
Now by default, we will not walk up the directory structure and possibly findgit directories that the user didn't intend to find.If required, that kind of behaviour can be turned back on.Fixesgitpython-developers#65
1 parentbfce49f commit96c6ab4

File tree

4 files changed

+16
-28
lines changed

4 files changed

+16
-28
lines changed

‎doc/source/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Changelog
88
* diff() can now properly detect renames, both in patch and raw format. Previously it only worked when create_patch was True.
99
* repo.odb.update_cache() is now called automatically after fetch and pull operations. In case you did that in your own code, you might want to remove your line to prevent a double-update that causes unnecessary IO.
1010
* A list of all fixed issues can be found here: https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v0.3.5+-+bugfixes%22+
11+
* `Repo(path)` will not automatically search upstream anymore and find any git directory on its way up. If you need that behaviour, you can turn it back on using the new `search_parent_directories=True` flag when constructing a `Repo` object.
1112

1213
0.3.4 - Python 3 Support
1314
========================

‎git/repo/base.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
rev_parse,
4747
is_git_dir,
4848
find_git_dir,
49-
read_gitfile,
5049
touch,
5150
)
5251
fromgit.compatimport (
@@ -96,7 +95,7 @@ class Repo(object):
9695
# represents the configuration level of a configuration file
9796
config_level= ("system","global","repository")
9897

99-
def__init__(self,path=None,odbt=DefaultDBType):
98+
def__init__(self,path=None,odbt=DefaultDBType,search_parent_directories=False):
10099
"""Create a new Repo instance
101100
102101
:param path: is the path to either the root git directory or the bare git repo::
@@ -128,15 +127,14 @@ def __init__(self, path=None, odbt=DefaultDBType):
128127
self.git_dir=curpath
129128
self._working_tree_dir=os.path.dirname(curpath)
130129
break
130+
131131
gitpath=find_git_dir(join(curpath,'.git'))
132132
ifgitpathisnotNone:
133133
self.git_dir=gitpath
134134
self._working_tree_dir=curpath
135135
break
136-
gitpath=read_gitfile(curpath)
137-
ifgitpath:
138-
self.git_dir=gitpath
139-
self._working_tree_dir=curpath
136+
137+
ifnotsearch_parent_directories:
140138
break
141139
curpath,dummy=os.path.split(curpath)
142140
ifnotdummy:

‎git/repo/fun.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
fromgit.compatimportxrange
2020

2121

22-
__all__= ('rev_parse','is_git_dir','touch','read_gitfile','find_git_dir','name_to_object',
23-
'short_to_long','deref_tag','to_commit')
22+
__all__= ('rev_parse','is_git_dir','touch','find_git_dir','name_to_object','short_to_long','deref_tag',
23+
'to_commit')
2424

2525

2626
deftouch(filename):
@@ -44,32 +44,21 @@ def is_git_dir(d):
4444
deffind_git_dir(d):
4545
ifis_git_dir(d):
4646
returnd
47-
elifisfile(d):
47+
48+
try:
4849
withopen(d)asfp:
4950
content=fp.read().rstrip()
51+
except (IOError,OSError):
52+
# it's probably not a file
53+
pass
54+
else:
5055
ifcontent.startswith('gitdir: '):
5156
d=join(dirname(d),content[8:])
5257
returnfind_git_dir(d)
58+
# end handle exception
5359
returnNone
5460

5561

56-
defread_gitfile(f):
57-
""" This is taken from the git setup.c:read_gitfile function.
58-
:return gitdir path or None if gitfile is invalid."""
59-
iffisNone:
60-
returnNone
61-
try:
62-
line=open(f,'r').readline().rstrip()
63-
except (OSError,IOError):
64-
# File might not exist or is unreadable - ignore
65-
returnNone
66-
# end handle file access
67-
ifline[0:8]!='gitdir: ':
68-
returnNone
69-
path=os.path.realpath(line[8:])
70-
returnpathifis_git_dir(path)elseNone
71-
72-
7362
defshort_to_long(odb,hexsha):
7463
""":return: long hexadecimal sha1 from the given less-than-40 byte hexsha
7564
or None if no candidate could be found.

‎git/test/performance/lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def setUp(self):
5656
"your choice - defaulting to the gitpython repository")
5757
repo_path=os.path.dirname(__file__)
5858
# end set some repo path
59-
self.gitrorepo=Repo(repo_path,odbt=GitCmdObjectDB)
60-
self.puregitrorepo=Repo(repo_path,odbt=GitDB)
59+
self.gitrorepo=Repo(repo_path,odbt=GitCmdObjectDB,search_parent_directories=True)
60+
self.puregitrorepo=Repo(repo_path,odbt=GitDB,search_parent_directories=True)
6161

6262
deftearDown(self):
6363
self.gitrorepo.git.clear_cache()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp