47
47
from .fun import (
48
48
rev_parse ,
49
49
is_git_dir ,
50
- find_git_dir ,
50
+ find_submodule_git_dir ,
51
51
touch ,
52
52
)
53
53
from git .compat import (
79
79
80
80
81
81
def _expand_path (p ):
82
- return os .path .abspath (os .path .expandvars (os .path .expanduser (p )))
82
+ return os .path .normpath ( os . path . abspath (os .path .expandvars (os .path .expanduser (p ) )))
83
83
84
84
85
85
class Repo (object ):
@@ -98,6 +98,11 @@ class Repo(object):
98
98
'git_dir' is the .git repository directory, which is always set."""
99
99
DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
100
100
101
+ git = None # Must exist, or __del__ will fail in case we raise on `__init__()`
102
+ working_dir = None
103
+ _working_tree_dir = None
104
+ git_dir = None
105
+
101
106
# precompiled regex
102
107
re_whitespace = re .compile (r'\s+' )
103
108
re_hexsha_only = re .compile ('^[0-9A-Fa-f]{40}$' )
@@ -138,16 +143,11 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
138
143
:raise InvalidGitRepositoryError:
139
144
:raise NoSuchPathError:
140
145
:return: git.Repo """
141
- self .git = None # should be set for __del__ not to fail in case we raise
142
146
epath = os .getenv ('GIT_DIR' )
143
147
epath = _expand_path (epath or path or os .getcwd ())
144
148
if not os .path .exists (epath ):
145
149
raise NoSuchPathError (epath )
146
150
147
- self .working_dir = None
148
- self ._working_tree_dir = None
149
- self .git_dir = None
150
-
151
151
## Walk up the path to find the `.git` dir.
152
152
#
153
153
curpath = epath
@@ -157,20 +157,20 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
157
157
# repo instances with paths that depend on path-portions that will not exist after being
158
158
# removed. It's just cleaner.
159
159
if is_git_dir (curpath ):
160
- self .git_dir = os . path . normpath ( curpath )
160
+ self .git_dir = curpath
161
161
self ._working_tree_dir = os .path .dirname (self .git_dir )
162
162
break
163
163
164
- gitpath = find_git_dir (join (curpath , '.git' ))
165
- if gitpath is not None :
166
- self .git_dir = os .path .normpath (gitpath )
164
+ sm_gitpath = find_submodule_git_dir (join (curpath , '.git' ))
165
+ if sm_gitpath is not None :
166
+ self .git_dir = os .path .normpath (sm_gitpath )
167
167
self ._working_tree_dir = curpath
168
168
break
169
169
170
170
if not search_parent_directories :
171
171
break
172
- curpath , dummy = os .path .split (curpath )
173
- if not dummy :
172
+ curpath , tail = os .path .split (curpath )
173
+ if not tail :
174
174
break
175
175
# END while curpath
176
176
0 commit comments