@@ -127,6 +127,10 @@ def _get_intermediate_items(self, item):
127127return list ()
128128# END handle intermeditate items
129129
130+ @classmethod
131+ def _need_gitfile_submodules (cls ,git ):
132+ return git .version_info [:3 ]>= (1 ,8 ,0 )
133+
130134def __eq__ (self ,other ):
131135"""Compare with another submodule"""
132136# 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):
157161 access of the config parser"""
158162parent_matches_head = repo .head .commit == parent_commit
159163if 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 )
163165else :
164166try :
165167fp_module = cls ._sio_modules (parent_commit )
@@ -198,6 +200,23 @@ def _config_parser_constrained(self, read_only):
198200parser .set_submodule (self )
199201return SectionConstraint (parser ,sm_section (self .name ))
200202
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+
201220#{ Edit Interface
202221
203222@classmethod
@@ -298,7 +317,17 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
298317if not branch_is_default :
299318kwargs ['b' ]= br .name
300319# 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 )
302331# END verify url
303332
304333# update configuration and index
@@ -390,7 +419,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
390419import git
391420
392421# 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 )
394423if not dry_run and os .path .isdir (module_path ):
395424try :
396425os .rmdir (module_path )