Skip to content

Commit

Permalink
submodule update: add convenience option --init
Browse files Browse the repository at this point in the history
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 <name>

When "update" is called without --init on an uninitialized submodule,
a hint to use --init is printed.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed May 16, 2008
1 parent b303178 commit be4d2c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Documentation/git-submodule.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ SYNOPSIS
[verse]
'git-submodule' [--quiet] add [-b branch] [--] <repository> [<path>]
'git-submodule' [--quiet] status [--cached] [--] [<path>...]
'git-submodule' [--quiet] [init|update] [--] [<path>...]
'git-submodule' [--quiet] init [--] [<path>...]
'git-submodule' [--quiet] update [--init] [--] [<path>...]
'git-submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]


Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Copyright (c) 2007 Lars Hjemli

USAGE="[--quiet] [--cached] \
[add <repo> [-b branch]|status|init|update|summary [-n|--summary-limit <n>] [<commit>]] \
[add <repo> [-b branch]|status|init|update [-i|--init]|summary [-n|--summary-limit <n>] [<commit>]] \
[--] [<path>...]"
OPTIONS_SPEC=
. git-sh-setup
Expand Down Expand Up @@ -271,6 +271,10 @@ cmd_update()
-q|--quiet)
quiet=1
;;
-i|--init)
shift
cmd_init "$@" || return
;;
--)
shift
break
Expand All @@ -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

Expand Down
13 changes: 13 additions & 0 deletions t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit be4d2c8

Please sign in to comment.