Skip to content

Commit ac1fbbd

Browse files
committed
submodule: do not copy unknown update mode from .gitmodules
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 <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5c1d2e8 commit ac1fbbd

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

git-submodule.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,21 @@ cmd_init()
612612
fi
613613

614614
# Copy "update" setting when it is not set yet
615-
upd="$(git config -f .gitmodules submodule."$name".update)"
616-
test -z "$upd" ||
617-
test -n "$(git config submodule."$name".update)" ||
618-
git config submodule."$name".update "$upd" ||
619-
die "$(eval_gettext "Failed to register update mode for submodule path '\$displaypath'")"
615+
if upd="$(git config -f .gitmodules submodule."$name".update)" &&
616+
test -n "$upd" &&
617+
test -z "$(git config submodule."$name".update)"
618+
then
619+
case "$upd" in
620+
rebase | merge | none)
621+
;; # known modes of updating
622+
*)
623+
echo >&2 "warning: unknown update mode '$upd' suggested for submodule '$name'"
624+
upd=none
625+
;;
626+
esac
627+
git config submodule."$name".update "$upd" ||
628+
die "$(eval_gettext "Failed to register update mode for submodule path '\$displaypath'")"
629+
fi
620630
done
621631
}
622632

t/t7406-submodule-update.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,21 @@ test_expect_success 'submodule update - command in .git/config catches failure'
323323
)
324324
'
325325

326+
test_expect_success 'submodule init does not copy command into .git/config' '
327+
(cd super &&
328+
H=$(git ls-files -s submodule | cut -d" " -f2) &&
329+
mkdir submodule1 &&
330+
git update-index --add --cacheinfo 160000 $H submodule1 &&
331+
git config -f .gitmodules submodule.submodule1.path submodule1 &&
332+
git config -f .gitmodules submodule.submodule1.url ../submodule &&
333+
git config -f .gitmodules submodule.submodule1.update !false &&
334+
git submodule init submodule1 &&
335+
echo "none" >expect &&
336+
git config submodule.submodule1.update >actual &&
337+
test_cmp expect actual
338+
)
339+
'
340+
326341
test_expect_success 'submodule init picks up rebase' '
327342
(cd super &&
328343
git config -f .gitmodules submodule.rebasing.update rebase &&

0 commit comments

Comments
 (0)