diff --git a/README-SUBMODULES.md b/README-SUBMODULES.md index f55797a..412e513 100644 --- a/README-SUBMODULES.md +++ b/README-SUBMODULES.md @@ -2,11 +2,21 @@ ## Introduction -Subrepositories must first be converted in order for the conversion of -the super repository to know how hg commits map to git commits in the -sub repositories. When all subrepositories have been converted, a -mapping file that maps the mercurial subrepository path to a converted -git submodule path must be created. The format for this file is: +hg-fast-export supports migrating mercurial subrepositories in the +repository being converted into git submodules in the converted repository. + +Git submodules must be git repositories while mercurial's subrepositories can +be git, mercurial or subversion repositories. hg-fast-export will handle any +git subrepositories automatically, any other kinds must first be converted +to git repositories. Currently hg-fast-export does not support the conversion +of subversion subrepositories. The rest of this page covers the conversion of +mercurial subrepositories which require some manual steps: + +The first step for mercurial subrepositories involves converting the +subrepository into a git repository using hg-fast-export. When all +subrepositories have been converted, a mapping file that maps the mercurial +subrepository path to a converted git submodule path must be created. The +format for this file is: ""="" ""="" diff --git a/hg-fast-export.py b/hg-fast-export.py index b7becbc..8e3449a 100755 --- a/hg-fast-export.py +++ b/hg-fast-export.py @@ -141,6 +141,13 @@ def remove_gitmodules(ctx): wr('D %s' % submodule) wr('D .gitmodules') +def refresh_git_submodule(name,subrepo_info): + wr('M 160000 %s %s' % (subrepo_info[1],name)) + sys.stderr.write("Adding/updating submodule %s, revision %s\n" + % (name,subrepo_info[1])) + return '[submodule "%s"]\n\tpath = %s\n\turl = %s\n' % (name,name, + subrepo_info[0]) + def refresh_hg_submodule(name,subrepo_info): gitRepoLocation=submodule_mappings[name] + "/.git" @@ -171,7 +178,9 @@ def refresh_gitmodules(ctx): gitmodules="" # Create the .gitmodules file and all submodules for name,subrepo_info in ctx.substate.items(): - if name in submodule_mappings: + if subrepo_info[2]=='git': + gitmodules+=refresh_git_submodule(name,subrepo_info) + elif submodule_mappings and name in submodule_mappings: gitmodules+=refresh_hg_submodule(name,subrepo_info) if len(gitmodules): @@ -183,7 +192,7 @@ def export_file_contents(ctx,manifest,files,hgtags,encoding='',plugins={}): count=0 max=len(files) for file in files: - if submodule_mappings and file==".hgsubstate": + if file==".hgsubstate": refresh_gitmodules(ctx) # Skip .hgtags files. They only get us in trouble. if not hgtags and file == ".hgtags":