submodule: ensure that -c http.extraheader is heeded
[gitweb.git] / git-submodule.sh
index b1c056c71567522e7b1bdb94bacf10f70743e024..b9469e7db6ed3bb4844727897325f1dd5380303f 100755 (executable)
@@ -602,6 +602,24 @@ cmd_deinit()
        done
 }
 
+is_tip_reachable () (
+       sanitize_submodule_env &&
+       cd "$1" &&
+       rev=$(git rev-list -n 1 "$2" --not --all 2>/dev/null) &&
+       test -z "$rev"
+)
+
+fetch_in_submodule () (
+       sanitize_submodule_env &&
+       cd "$1" &&
+       case "$2" in
+       '')
+               git fetch ;;
+       *)
+               git fetch $(get_default_remote) "$2" ;;
+       esac
+)
+
 #
 # Update each submodule path to correct revision, using clone and checkout as needed
 #
@@ -756,10 +774,15 @@ Maybe you want to use 'update --init'?")"
                        then
                                # Run fetch only if $sha1 isn't present or it
                                # is not reachable from a ref.
-                               (sanitize_submodule_env; cd "$sm_path" &&
-                                       ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
-                                        test -z "$rev") || git-fetch)) ||
+                               is_tip_reachable "$sm_path" "$sha1" ||
+                               fetch_in_submodule "$sm_path" ||
                                die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
+
+                               # Now we tried the usual fetch, but $sha1 may
+                               # not be reachable from any of the refs
+                               is_tip_reachable "$sm_path" "$sha1" ||
+                               fetch_in_submodule "$sm_path" "$sha1" ||
+                               die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain $sha1. Direct fetching of that commit failed.")"
                        fi
 
                        # Is this something we just cloned?