]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule: do not copy unknown update mode from .gitmodules
authorJunio C Hamano <gitster@pobox.com>
Mon, 2 Dec 2013 21:31:55 +0000 (13:31 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Dec 2013 21:48:06 +0000 (13:48 -0800)
When submodule.$name.update is given as hint from the upstream in
the .gitmodules file, we used to blindly copy it to .git/config,
unless there already is a value defined for the submodule.

However, there is no reason to expect that the update mode hinted by
the upstream is available in the version of Git the user is using,
and a really custom "!cmd" prepared by an upstream person running on
Linux may not even be available to a user on Windows.  It is simply
irresponsible to copy the setting blindly and to attempt to use it
during a later "submodule update" without validating it first.

Just show the suggested value to the diagnostic output, and set the
value to 'none' in the configuration, if it is not one of the ones
that are known to be supported by this version of Git.

Helped-by: Jens Lehmann <Jens.Lehmann@web.de>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-submodule.sh
t/t7406-submodule-update.sh

index 2979197087f2c6d97e2945008394d50c16a195a5..83917d8055d4c009664a88cfb97eeb5f5b2577b5 100755 (executable)
@@ -612,11 +612,21 @@ cmd_init()
                fi
 
                # Copy "update" setting when it is not set yet
-               upd="$(git config -f .gitmodules submodule."$name".update)"
-               test -z "$upd" ||
-               test -n "$(git config submodule."$name".update)" ||
-               git config submodule."$name".update "$upd" ||
-               die "$(eval_gettext "Failed to register update mode for submodule path '\$displaypath'")"
+               if upd="$(git config -f .gitmodules submodule."$name".update)" &&
+                  test -n "$upd" &&
+                  test -z "$(git config submodule."$name".update)"
+               then
+                       case "$upd" in
+                       rebase | merge | none)
+                               ;; # known modes of updating
+                       *)
+                               echo >&2 "warning: unknown update mode '$upd' suggested for submodule '$name'"
+                               upd=none
+                               ;;
+                       esac
+                       git config submodule."$name".update "$upd" ||
+                       die "$(eval_gettext "Failed to register update mode for submodule path '\$displaypath'")"
+               fi
        done
 }
 
index f0b33053ab01c692a4dda15c0f631aaa45fb81b9..0825a928dfa2a340f6fce6e2313324bd5d63ea7f 100755 (executable)
@@ -323,6 +323,21 @@ test_expect_success 'submodule update - command in .git/config catches failure'
        )
 '
 
+test_expect_success 'submodule init does not copy command into .git/config' '
+       (cd super &&
+        H=$(git ls-files -s submodule | cut -d" " -f2) &&
+        mkdir submodule1 &&
+        git update-index --add --cacheinfo 160000 $H submodule1 &&
+        git config -f .gitmodules submodule.submodule1.path submodule1 &&
+        git config -f .gitmodules submodule.submodule1.url ../submodule &&
+        git config -f .gitmodules submodule.submodule1.update !false &&
+        git submodule init submodule1 &&
+        echo "none" >expect &&
+        git config submodule.submodule1.update >actual &&
+        test_cmp expect actual
+       )
+'
+
 test_expect_success 'submodule init picks up rebase' '
        (cd super &&
         git config -f .gitmodules submodule.rebasing.update rebase &&