submodule.c: submodule_move_head works with broken submodules
[gitweb.git] / git-submodule.sh
index 577136148f7601895d1e819da560549ad11443d2..6ec35e5fcd2696fb13c099a22e4a01b87042438e 100755 (executable)
@@ -278,6 +278,20 @@ or you are unsure what this means choose another name with the '--name' option."
        fi &&
        git add --force .gitmodules ||
        die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
+
+       # NEEDSWORK: In a multi-working-tree world, this needs to be
+       # set in the per-worktree config.
+       if git config --get submodule.active >/dev/null
+       then
+               # If the submodule being adding isn't already covered by the
+               # current configured pathspec, set the submodule's active flag
+               if ! git submodule--helper is-active "$sm_path"
+               then
+                       git config submodule."$sm_name".active "true"
+               fi
+       else
+               git config submodule."$sm_name".active "true"
+       fi
 }
 
 #
@@ -1089,14 +1103,14 @@ cmd_sync()
        while read mode sha1 stage sm_path
        do
                die_if_unmatched "$mode" "$sha1"
-               name=$(git submodule--helper name "$sm_path")
 
                # skip inactive submodules
-               if ! git config "submodule.$name.url" >/dev/null 2>/dev/null
+               if ! git submodule--helper is-active "$sm_path"
                then
                        continue
                fi
 
+               name=$(git submodule--helper name "$sm_path")
                url=$(git config -f .gitmodules --get submodule."$name".url)
 
                # Possibly a url relative to parent