Merge branch 'sb/submodule-deinit-all' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 31 May 2016 21:09:46 +0000 (14:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 May 2016 21:09:46 +0000 (14:09 -0700)
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

1  2 
git-submodule.sh
t/t7400-submodule-basic.sh
diff --combined git-submodule.sh
index 753a90d3071d1917495ca725fe15a944f84b6f60,fb68f1fa7c35aa319737e8e51e23873a20f9fa4c..d56207ea05db971f8ebdf566848b31df86b81c64
@@@ -8,7 -8,7 +8,7 @@@ dashless=$(basename "$0" | sed -e 's/-
  USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
     or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] init [--] [<path>...]
-    or: $dashless [--quiet] deinit [-f|--force] [--] <path>...
+    or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
     or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
     or: $dashless [--quiet] foreach [--recursive] <command>
@@@ -413,8 -413,8 +413,8 @@@ cmd_foreach(
                die_if_unmatched "$mode"
                if test -e "$sm_path"/.git
                then
 -                      displaypath=$(relative_path "$sm_path")
 -                      say "$(eval_gettext "Entering '\$prefix\$displaypath'")"
 +                      displaypath=$(relative_path "$prefix$sm_path")
 +                      say "$(eval_gettext "Entering '\$displaypath'")"
                        name=$(git submodule--helper name "$sm_path")
                        (
                                prefix="$prefix$sm_path/"
                                        cmd_foreach "--recursive" "$@"
                                fi
                        ) <&3 3<&- ||
 -                      die "$(eval_gettext "Stopping at '\$prefix\$displaypath'; script returned non-zero status.")"
 +                      die "$(eval_gettext "Stopping at '\$displaypath'; script returned non-zero status.")"
                fi
        done
  }
@@@ -473,7 -473,7 +473,7 @@@ cmd_init(
                die_if_unmatched "$mode"
                name=$(git submodule--helper name "$sm_path") || exit
  
 -              displaypath=$(relative_path "$sm_path")
 +              displaypath=$(relative_path "$prefix$sm_path")
  
                # Copy url setting when it is not set yet
                if test -z "$(git config "submodule.$name.url")"
  cmd_deinit()
  {
        # parse $args after "submodule ... deinit".
+       deinit_all=
        while test $# -ne 0
        do
                case "$1" in
                -q|--quiet)
                        GIT_QUIET=1
                        ;;
+               --all)
+                       deinit_all=t
+                       ;;
                --)
                        shift
                        break
                shift
        done
  
-       if test $# = 0
+       if test -n "$deinit_all" && test "$#" -ne 0
+       then
+               echo >&2 "$(eval_gettext "pathspec and --all are incompatible")"
+               usage
+       fi
+       if test $# = 0 && test -z "$deinit_all"
        then
-               die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")"
+               die "$(eval_gettext "Use '--all' if you really want to deinitialize all submodules")"
        fi
  
        git submodule--helper list --prefix "$wt_prefix" "$@" |
@@@ -802,8 -811,8 +811,8 @@@ Maybe you want to use 'update --init'?"
                                ;;
                        !*)
                                command="${update_module#!}"
 -                              die_msg="$(eval_gettext "Execution of '\$command \$sha1' failed in submodule path '\$prefix\$sm_path'")"
 -                              say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': '\$command \$sha1'")"
 +                              die_msg="$(eval_gettext "Execution of '\$command \$sha1' failed in submodule path '\$displaypath'")"
 +                              say_msg="$(eval_gettext "Submodule path '\$displaypath': '\$command \$sha1'")"
                                must_die_on_failure=yes
                                ;;
                        *)
@@@ -1159,7 -1168,6 +1168,7 @@@ cmd_status(
                        (
                                prefix="$displaypath/"
                                clear_local_git_env
 +                              wt_prefix=
                                cd "$sm_path" &&
                                eval cmd_status
                        ) ||
index a41be3142e85112af7de1c2e865b7b2e261e7ebd,cc3cca09f3743eab042e61804048c4b7b9ef6ad8..75db02389885d74942e0b20da55796130c0d2c62
@@@ -11,6 -11,10 +11,10 @@@ subcommands of git submodule
  
  . ./test-lib.sh
  
+ test_expect_success 'submodule deinit works on empty repository' '
+       git submodule deinit --all
+ '
  test_expect_success 'setup - initial commit' '
        >t &&
        git add t &&
@@@ -818,47 -822,6 +822,47 @@@ test_expect_success 'submodule add --na
        )
  '
  
 +test_expect_success 'recursive relative submodules stay relative' '
 +      test_when_finished "rm -rf super clone2 subsub sub3" &&
 +      mkdir subsub &&
 +      (
 +              cd subsub &&
 +              git init &&
 +              >t &&
 +              git add t &&
 +              git commit -m "initial commit"
 +      ) &&
 +      mkdir sub3 &&
 +      (
 +              cd sub3 &&
 +              git init &&
 +              >t &&
 +              git add t &&
 +              git commit -m "initial commit" &&
 +              git submodule add ../subsub dirdir/subsub &&
 +              git commit -m "add submodule subsub"
 +      ) &&
 +      mkdir super &&
 +      (
 +              cd super &&
 +              git init &&
 +              >t &&
 +              git add t &&
 +              git commit -m "initial commit" &&
 +              git submodule add ../sub3 &&
 +              git commit -m "add submodule sub"
 +      ) &&
 +      git clone super clone2 &&
 +      (
 +              cd clone2 &&
 +              git submodule update --init --recursive &&
 +              echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
 +              echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
 +      ) &&
 +      test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
 +      test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
 +'
 +
  test_expect_success 'submodule add with an existing name fails unless forced' '
        (
                cd addtest2 &&
@@@ -899,7 -862,8 +903,8 @@@ test_expect_success 'submodule deinit w
                >file &&
                git add file &&
                git commit -m "repo should not be empty"
-               git submodule deinit .
+               git submodule deinit . &&
+               git submodule deinit --all
        )
  '
  
@@@ -941,6 -905,19 +946,19 @@@ test_expect_success 'submodule deinit 
        rmdir init example2
  '
  
+ test_expect_success 'submodule deinit --all deinits all initialized submodules' '
+       git submodule update --init &&
+       git config submodule.example.foo bar &&
+       git config submodule.example2.frotz nitfol &&
+       test_must_fail git submodule deinit &&
+       git submodule deinit --all >actual &&
+       test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test -z "$(git config --get-regexp "submodule\.example2\.")" &&
+       test_i18ngrep "Cleared directory .init" actual &&
+       test_i18ngrep "Cleared directory .example2" actual &&
+       rmdir init example2
+ '
  test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
        git submodule update --init &&
        rm -rf init example2/* example2/.git &&
@@@ -1007,6 -984,10 +1025,10 @@@ test_expect_success 'submodule deinit i
        test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
        test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
        test_i18ngrep "Cleared directory .init" actual &&
+       git submodule deinit --all >actual &&
+       test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
+       test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
+       test_i18ngrep "Cleared directory .init" actual &&
        rmdir init example2
  '