Skip to content

Commit 3296e1a

Browse files
committed
Merge branch 'sb/submodule-deinit-all' into maint
Correct faulty recommendation to use "git submodule deinit ." when de-initialising all submodules, which would result in a strange error message in a pathological corner case. * sb/submodule-deinit-all: submodule deinit: require '--all' instead of '.' for all submodules
2 parents e646a82 + f6a5279 commit 3296e1a

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

Documentation/git-submodule.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
[--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
1414
'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
1515
'git submodule' [--quiet] init [--] [<path>...]
16-
'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
16+
'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...)
1717
'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
1818
[-f|--force] [--rebase|--merge] [--reference <repository>]
1919
[--depth <depth>] [--recursive] [--] [<path>...]
@@ -140,12 +140,15 @@ deinit::
140140
tree. Further calls to `git submodule update`, `git submodule foreach`
141141
and `git submodule sync` will skip any unregistered submodules until
142142
they are initialized again, so use this command if you don't want to
143-
have a local checkout of the submodule in your work tree anymore. If
143+
have a local checkout of the submodule in your working tree anymore. If
144144
you really want to remove a submodule from the repository and commit
145145
that use linkgit:git-rm[1] instead.
146146
+
147-
If `--force` is specified, the submodule's work tree will be removed even if
148-
it contains local modifications.
147+
When the command is run without pathspec, it errors out,
148+
instead of deinit-ing everything, to prevent mistakes.
149+
+
150+
If `--force` is specified, the submodule's working tree will
151+
be removed even if it contains local modifications.
149152

150153
update::
151154
+
@@ -247,6 +250,10 @@ OPTIONS
247250
--quiet::
248251
Only print error messages.
249252

253+
--all::
254+
This option is only valid for the deinit command. Unregister all
255+
submodules in the working tree.
256+
250257
-b::
251258
--branch::
252259
Branch of repository to add as submodule.
@@ -257,8 +264,8 @@ OPTIONS
257264
--force::
258265
This option is only valid for add, deinit and update commands.
259266
When running add, allow adding an otherwise ignored submodule path.
260-
When running deinit the submodule work trees will be removed even if
261-
they contain local changes.
267+
When running deinit the submodule working trees will be removed even
268+
if they contain local changes.
262269
When running update (only effective with the checkout procedure),
263270
throw away local changes in submodules when switching to a
264271
different commit; and always run a checkout operation in the

git-submodule.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dashless=$(basename "$0" | sed -e 's/-/ /')
88
USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
99
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
1010
or: $dashless [--quiet] init [--] [<path>...]
11-
or: $dashless [--quiet] deinit [-f|--force] [--] <path>...
11+
or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
1212
or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...]
1313
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
1414
or: $dashless [--quiet] foreach [--recursive] <command>
@@ -521,6 +521,7 @@ cmd_init()
521521
cmd_deinit()
522522
{
523523
# parse $args after "submodule ... deinit".
524+
deinit_all=
524525
while test $# -ne 0
525526
do
526527
case "$1" in
@@ -530,6 +531,9 @@ cmd_deinit()
530531
-q|--quiet)
531532
GIT_QUIET=1
532533
;;
534+
--all)
535+
deinit_all=t
536+
;;
533537
--)
534538
shift
535539
break
@@ -544,9 +548,14 @@ cmd_deinit()
544548
shift
545549
done
546550

547-
if test $# = 0
551+
if test -n "$deinit_all" && test "$#" -ne 0
552+
then
553+
echo >&2 "$(eval_gettext "pathspec and --all are incompatible")"
554+
usage
555+
fi
556+
if test $# = 0 && test -z "$deinit_all"
548557
then
549-
die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")"
558+
die "$(eval_gettext "Use '--all' if you really want to deinitialize all submodules")"
550559
fi
551560

552561
git submodule--helper list --prefix "$wt_prefix" "$@" |

t/t7400-submodule-basic.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ subcommands of git submodule.
1111

1212
. ./test-lib.sh
1313

14+
test_expect_success 'submodule deinit works on empty repository' '
15+
git submodule deinit --all
16+
'
17+
1418
test_expect_success 'setup - initial commit' '
1519
>t &&
1620
git add t &&
@@ -899,7 +903,8 @@ test_expect_success 'submodule deinit works on repository without submodules' '
899903
>file &&
900904
git add file &&
901905
git commit -m "repo should not be empty"
902-
git submodule deinit .
906+
git submodule deinit . &&
907+
git submodule deinit --all
903908
)
904909
'
905910

@@ -941,6 +946,19 @@ test_expect_success 'submodule deinit . deinits all initialized submodules' '
941946
rmdir init example2
942947
'
943948

949+
test_expect_success 'submodule deinit --all deinits all initialized submodules' '
950+
git submodule update --init &&
951+
git config submodule.example.foo bar &&
952+
git config submodule.example2.frotz nitfol &&
953+
test_must_fail git submodule deinit &&
954+
git submodule deinit --all >actual &&
955+
test -z "$(git config --get-regexp "submodule\.example\.")" &&
956+
test -z "$(git config --get-regexp "submodule\.example2\.")" &&
957+
test_i18ngrep "Cleared directory .init" actual &&
958+
test_i18ngrep "Cleared directory .example2" actual &&
959+
rmdir init example2
960+
'
961+
944962
test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
945963
git submodule update --init &&
946964
rm -rf init example2/* example2/.git &&
@@ -1007,6 +1025,10 @@ test_expect_success 'submodule deinit is silent when used on an uninitialized su
10071025
test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
10081026
test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
10091027
test_i18ngrep "Cleared directory .init" actual &&
1028+
git submodule deinit --all >actual &&
1029+
test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1030+
test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1031+
test_i18ngrep "Cleared directory .init" actual &&
10101032
rmdir init example2
10111033
'
10121034

0 commit comments

Comments
 (0)