8 git-submodule-auto-add - Automatically add submodules to a git repo according to .gitmodules file
12 git submodule-auto-add [I<OPTIONS>]
16 Those which git-submodule(1) B<add> accepts.
20 Call as many C<git submodule add ...> commands as many submodules are defined in
21 F<.gitmodules> file in the current repo's root.
22 Automatically adding submodules this way.
24 An extra feature is to able to define on which name the submodule's remote should
25 be called ("origin" or the tracking remote of superproject's current branch,
26 see git-submodule(1) for details). Add B<remotename> option to the submodule's section
27 in F<.gitmodules> to achieve this.
31 Does not fail if a submodule can not be added, but continues with the next one.
42 reporoot
=`git rev-parse --show-toplevel`
46 git config
-f "$reporoot"/.gitmodules
--get "$1" || true
49 git config
-f "$reporoot"/.gitmodules
--get-regexp '^submodule\..*\.path$' |\
50 while read -r path_key local_path
56 url_key
=${path_key/.path/.url}
57 branch_key
=${path_key/.path/.branch}
59 url
=`_gitconf "$url_key"`
60 branch
=`_gitconf "$branch_key"`
62 gitparams
=(submodule add
${branch:+-b "$branch"} "$@" "$url" "$local_path")
63 echo "+ git ${gitparams[*]}" >&2
66 # set the submodule's origin remote name to the one configured
67 # in submodule.<SM_NAME>.remotename - if any
69 remotename_key
=${path_key/.path/.remotename}
70 remotename
=`_gitconf "$remotename_key"`
72 if [ -n "$remotename" ]
74 local_path
=$local_path remotename
=$remotename git submodule foreach
'
75 [ "$sm_path" != "$local_path" ] && exit;
76 git remote | grep -qFx "$remotename" && exit;
77 git remote rename origin "$remotename";