From be4d2c83b68a96285cc05036add4d64d324e52d9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 16 May 2008 11:23:03 +0100 Subject: [PATCH] submodule update: add convenience option --init When a submodule is not initialized and you do not want to change the defaults from .gitmodules anyway, you can now say $ git submodule update --init When "update" is called without --init on an uninitialized submodule, a hint to use --init is printed. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-submodule.txt | 7 ++++++- git-submodule.sh | 7 ++++++- t/t7400-submodule-basic.sh | 13 +++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index 6ffd896fb..0668f295e 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -11,7 +11,8 @@ SYNOPSIS [verse] 'git-submodule' [--quiet] add [-b branch] [--] [] 'git-submodule' [--quiet] status [--cached] [--] [...] -'git-submodule' [--quiet] [init|update] [--] [...] +'git-submodule' [--quiet] init [--] [...] +'git-submodule' [--quiet] update [--init] [--] [...] 'git-submodule' [--quiet] summary [--summary-limit ] [commit] [--] [...] @@ -47,6 +48,10 @@ update:: Update the registered submodules, i.e. clone missing submodules and checkout the commit specified in the index of the containing repository. This will make the submodules HEAD be detached. ++ +If the submodule is not yet initialized, and you just want to use the +setting as stored in .gitmodules, you can automatically initialize the +submodule with the --init option. summary:: Show commit summary between the given commit (defaults to HEAD) and diff --git a/git-submodule.sh b/git-submodule.sh index b4b7d28d9..100737210 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -5,7 +5,7 @@ # Copyright (c) 2007 Lars Hjemli USAGE="[--quiet] [--cached] \ -[add [-b branch]|status|init|update|summary [-n|--summary-limit ] []] \ +[add [-b branch]|status|init|update [-i|--init]|summary [-n|--summary-limit ] []] \ [--] [...]" OPTIONS_SPEC= . git-sh-setup @@ -271,6 +271,10 @@ cmd_update() -q|--quiet) quiet=1 ;; + -i|--init) + shift + cmd_init "$@" || return + ;; --) shift break @@ -296,6 +300,7 @@ cmd_update() # path have been specified test "$#" != "0" && say "Submodule path '$path' not initialized" + say "Maybe you want to use 'update --init'?" continue fi diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 2ef85a869..6c7b90248 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -196,4 +196,17 @@ test_expect_success 'apply submodule diff' ' test -z "$D" ' +test_expect_success 'update --init' ' + + mv init init2 && + git config -f .gitmodules submodule.example.url "$(pwd)/init2" && + git config --remove-section submodule.example + git submodule update init > update.out && + grep "not initialized" update.out && + test ! -d init/.git && + git submodule update --init init && + test -d init/.git + +' + test_done -- 2.30.2