File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ def __init__(self, path=None):
8888 while curpath :
8989 if is_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 if is_git_dir (gitpath ):
@@ -99,16 +99,21 @@ def __init__(self, path=None):
9999 if not dummy :
100100 break
101101 # END while curpath
102+
103+ if self .path is None :
104+ raise InvalidGitRepositoryError (epath )
102105
103106 self ._bare = False
104107 try :
105108 self ._bare = self .config_reader ("repository" ).getboolean ('core' ,'bare' )
106109 except Exception :
107110 # lets not assume the option exists, although it should
108111 pass
109-
110- if self .path is None :
111- raise InvalidGitRepositoryError (epath )
112+
113+ # adjust the wd in case we are actually bare - we didn't know that
114+ # in the first place
115+ if self ._bare :
116+ self .wd = self .path
112117
113118 self .git = Git (self .wd )
114119
Original file line number Diff line number Diff line change @@ -20,6 +20,13 @@ def test_new_should_raise_on_invalid_repo_location(self):
2020 def test_new_should_raise_on_non_existant_path (self ):
2121 Repo ("repos/foobar" )
2222
23+ def test_repo_creation_from_different_paths (self ):
24+ r_from_gitdir = Repo (self .rorepo .path )
25+ assert r_from_gitdir .path == self .rorepo .path
26+ assert r_from_gitdir .path .endswith ('.git' )
27+ assert not self .rorepo .git .git_dir .endswith ('.git' )
28+ assert r_from_gitdir .git .git_dir == self .rorepo .git .git_dir
29+
2330 def test_description (self ):
2431 txt = "Test repository"
2532 self .rorepo .description = txt
You can’t perform that action at this time.
0 commit comments