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

Commit1eae9d1

Browse files
committed
repo: fixed incorrect path handling thta could lead to issues if the repository was initialized with a .git repository, although it was not bare actually
1 parentbae67b8 commit1eae9d1

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

‎lib/git/cmd.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ def __init__(self, git_dir=None):
9898
9999
``git_dir``
100100
Git directory we should work in. If None, we always work in the current
101-
directory as returned by os.getcwd()
101+
directory as returned by os.getcwd().
102+
It is meant to be the working tree directory if available, or the
103+
.git directory in case of bare repositories.
102104
"""
103105
super(Git,self).__init__()
104106
self.git_dir=git_dir

‎lib/git/repo.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def __init__(self, path=None):
8888
whilecurpath:
8989
ifis_git_dir(curpath):
9090
self.path=curpath
91-
self.wd=curpath
91+
self.wd=os.path.dirname(curpath)
9292
break
9393
gitpath=os.path.join(curpath,'.git')
9494
ifis_git_dir(gitpath):
@@ -99,16 +99,21 @@ def __init__(self, path=None):
9999
ifnotdummy:
100100
break
101101
# END while curpath
102+
103+
ifself.pathisNone:
104+
raiseInvalidGitRepositoryError(epath)
102105

103106
self._bare=False
104107
try:
105108
self._bare=self.config_reader("repository").getboolean('core','bare')
106109
exceptException:
107110
# lets not assume the option exists, although it should
108111
pass
109-
110-
ifself.pathisNone:
111-
raiseInvalidGitRepositoryError(epath)
112+
113+
# adjust the wd in case we are actually bare - we didn't know that
114+
# in the first place
115+
ifself._bare:
116+
self.wd=self.path
112117

113118
self.git=Git(self.wd)
114119

‎test/git/test_repo.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ def test_new_should_raise_on_invalid_repo_location(self):
2020
deftest_new_should_raise_on_non_existant_path(self):
2121
Repo("repos/foobar")
2222

23+
deftest_repo_creation_from_different_paths(self):
24+
r_from_gitdir=Repo(self.rorepo.path)
25+
assertr_from_gitdir.path==self.rorepo.path
26+
assertr_from_gitdir.path.endswith('.git')
27+
assertnotself.rorepo.git.git_dir.endswith('.git')
28+
assertr_from_gitdir.git.git_dir==self.rorepo.git.git_dir
29+
2330
deftest_description(self):
2431
txt="Test repository"
2532
self.rorepo.description=txt

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp