@@ -127,6 +127,10 @@ def _get_intermediate_items(self, item):
127
127
return list ()
128
128
# END handle intermeditate items
129
129
130
+ @classmethod
131
+ def _need_gitfile_submodules (cls , git ):
132
+ return git .version_info [:3 ] >= (1 , 8 , 0 )
133
+
130
134
def __eq__ (self , other ):
131
135
"""Compare with another submodule"""
132
136
# we may only compare by name as this should be the ID they are hashed with
@@ -157,9 +161,7 @@ def _config_parser(cls, repo, parent_commit, read_only):
157
161
access of the config parser"""
158
162
parent_matches_head = repo .head .commit == parent_commit
159
163
if not repo .bare and parent_matches_head :
160
- fp_module = cls .k_modules_file
161
- fp_module_path = os .path .join (repo .working_tree_dir , fp_module )
162
- fp_module = fp_module_path
164
+ fp_module = os .path .join (repo .working_tree_dir , cls .k_modules_file )
163
165
else :
164
166
try :
165
167
fp_module = cls ._sio_modules (parent_commit )
@@ -198,6 +200,23 @@ def _config_parser_constrained(self, read_only):
198
200
parser .set_submodule (self )
199
201
return SectionConstraint (parser , sm_section (self .name ))
200
202
203
+ @classmethod
204
+ def _module_abspath (cls , parent_repo , path , name ):
205
+ if cls ._need_gitfile_submodules (parent_repo .git ):
206
+ return os .path .join (parent_repo .git_dir , 'modules' , name )
207
+ else :
208
+ return os .path .join (parent_repo .working_tree_dir , path )
209
+ # end
210
+
211
+ @classmethod
212
+ def _write_git_file (cls , working_tree_dir , module_abspath , overwrite_existing = False ):
213
+ """Writes a .git file containing a (preferably) relative path to the actual git module repository.
214
+ It is an error if the module_abspath cannot be made into a relative path, relative to the working_tree_dir
215
+ :param working_tree_dir: directory to write the .git file into
216
+ :param module_abspath: absolute path to the bare repository
217
+ :param overwrite_existing: if True, we may rewrite existing .git files, otherwise we raise"""
218
+ raise NotImplementedError
219
+
201
220
#{ Edit Interface
202
221
203
222
@classmethod
@@ -298,7 +317,17 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
298
317
if not branch_is_default :
299
318
kwargs ['b' ] = br .name
300
319
# END setup checkout-branch
301
- mrepo = git .Repo .clone_from (url , os .path .join (repo .working_tree_dir , path ), ** kwargs )
320
+ module_abspath = cls ._module_abspath (repo , path , name )
321
+ module_checkout_path = module_abspath
322
+ if cls ._need_gitfile_submodules (repo .git ):
323
+ kwargs ['separate_git_dir' ] = module_abspath
324
+ module_abspath_dir = os .path .dirname (module_abspath )
325
+ if not os .path .isdir (module_abspath_dir ):
326
+ os .makedirs (module_abspath_dir )
327
+ module_checkout_path = os .path .join (repo .working_tree_dir , path )
328
+ # end
329
+
330
+ mrepo = git .Repo .clone_from (url , module_checkout_path , ** kwargs )
302
331
# END verify url
303
332
304
333
# update configuration and index
@@ -390,7 +419,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
390
419
import git
391
420
392
421
# there is no git-repository yet - but delete empty paths
393
- module_path = join_path_native (self .repo . working_tree_dir , self .path )
422
+ module_path = self . _module_abspath (self .repo , self .path , self . name )
394
423
if not dry_run and os .path .isdir (module_path ):
395
424
try :
396
425
os .rmdir (module_path )
0 commit comments