Merge branch 'jl/submodule-deinit'
authorJunio C Hamano <gitster@pobox.com>
Fri, 5 Apr 2013 21:15:13 +0000 (14:15 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Apr 2013 21:15:13 +0000 (14:15 -0700)
A finishing touch to the new topic in 1.8.3.

* jl/submodule-deinit:
submodule deinit: clarify work tree removal message

1  2 
git-submodule.sh
t/t7400-submodule-basic.sh
diff --combined git-submodule.sh
index 275c664ff55f2d669ad302f0b11d8629b2d7d1ec,59ac86f34561ac6adc8898fcc80f6b66961838bf..79bfaac9d4cb9a04e5e1fd7675d740cf9fc27e87
@@@ -9,7 -9,7 +9,7 @@@ USAGE="[--quiet] add [-b <branch>] [-f|
     or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] init [--] [<path>...]
     or: $dashless [--quiet] deinit [-f|--force] [--] <path>...
 -   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
 +   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
     or: $dashless [--quiet] foreach [--recursive] <command>
     or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
@@@ -27,7 -27,6 +27,7 @@@ cached
  recursive=
  init=
  files=
 +remote=
  nofetch=
  update=
  prefix=
@@@ -154,32 -153,6 +154,32 @@@ die_if_unmatched (
        fi
  }
  
 +#
 +# Print a submodule configuration setting
 +#
 +# $1 = submodule name
 +# $2 = option name
 +# $3 = default value
 +#
 +# Checks in the usual git-config places first (for overrides),
 +# otherwise it falls back on .gitmodules.  This allows you to
 +# distribute project-wide defaults in .gitmodules, while still
 +# customizing individual repositories if necessary.  If the option is
 +# not in .gitmodules either, print a default value.
 +#
 +get_submodule_config () {
 +      name="$1"
 +      option="$2"
 +      default="$3"
 +      value=$(git config submodule."$name"."$option")
 +      if test -z "$value"
 +      then
 +              value=$(git config -f .gitmodules submodule."$name"."$option")
 +      fi
 +      printf '%s' "${value:-$default}"
 +}
 +
 +
  #
  # Map submodule path to submodule name
  #
@@@ -267,11 -240,6 +267,11 @@@ module_clone(
        (clear_local_git_env; cd "$sm_path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
  }
  
 +isnumber()
 +{
 +      n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
 +}
 +
  #
  # Add a new submodule to the working tree, .gitmodules and the index
  #
@@@ -423,10 -391,6 +423,10 @@@ Use -f if you really want to add it." >
  
        git config -f .gitmodules submodule."$sm_name".path "$sm_path" &&
        git config -f .gitmodules submodule."$sm_name".url "$repo" &&
 +      if test -n "$branch"
 +      then
 +              git config -f .gitmodules submodule."$sm_name".branch "$branch"
 +      fi &&
        git add --force .gitmodules ||
        die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
  }
@@@ -606,10 -570,12 +606,12 @@@ cmd_deinit(
  
                        if test -z "$force"
                        then
-                               git rm -n "$sm_path" ||
+                               git rm -qn "$sm_path" ||
                                die "$(eval_gettext "Submodule work tree '\$sm_path' contains local modifications; use '-f' to discard them")"
                        fi
-                       rm -rf "$sm_path" || say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")"
+                       rm -rf "$sm_path" &&
+                       say "$(eval_gettext "Cleared directory '\$sm_path'")" ||
+                       say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")"
                fi
  
                mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$sm_path'")"
@@@ -644,9 -610,6 +646,9 @@@ cmd_update(
                -i|--init)
                        init=1
                        ;;
 +              --remote)
 +                      remote=1
 +                      ;;
                -N|--no-fetch)
                        nofetch=1
                        ;;
                die_if_unmatched "$mode"
                if test "$stage" = U
                then
 -                      echo >&2 "Skipping unmerged submodule $sm_path"
 +                      echo >&2 "Skipping unmerged submodule $prefix$sm_path"
                        continue
                fi
                name=$(module_name "$sm_path") || exit
                url=$(git config submodule."$name".url)
 +              branch=$(get_submodule_config "$name" branch master)
                if ! test -z "$update"
                then
                        update_module=$update
  
                if test "$update_module" = "none"
                then
 -                      echo "Skipping submodule '$sm_path'"
 +                      echo "Skipping submodule '$prefix$sm_path'"
                        continue
                fi
  
                        # Only mention uninitialized submodules when its
                        # path have been specified
                        test "$#" != "0" &&
 -                      say "$(eval_gettext "Submodule path '\$sm_path' not initialized
 +                      say "$(eval_gettext "Submodule path '\$prefix\$sm_path' not initialized
  Maybe you want to use 'update --init'?")"
                        continue
                fi
                else
                        subsha1=$(clear_local_git_env; cd "$sm_path" &&
                                git rev-parse --verify HEAD) ||
 -                      die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"
 +                      die "$(eval_gettext "Unable to find current revision in submodule path '\$prefix\$sm_path'")"
 +              fi
 +
 +              if test -n "$remote"
 +              then
 +                      if test -z "$nofetch"
 +                      then
 +                              # Fetch remote before determining tracking $sha1
 +                              (clear_local_git_env; cd "$sm_path" && git-fetch) ||
 +                              die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
 +                      fi
 +                      remote_name=$(clear_local_git_env; cd "$sm_path" && get_default_remote)
 +                      sha1=$(clear_local_git_env; cd "$sm_path" &&
 +                              git rev-parse --verify "${remote_name}/${branch}") ||
 +                      die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
                fi
  
                if test "$subsha1" != "$sha1" -o -n "$force"
                                (clear_local_git_env; cd "$sm_path" &&
                                        ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
                                         test -z "$rev") || git-fetch)) ||
 -                              die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
 +                              die "$(eval_gettext "Unable to fetch in submodule path '\$prefix\$sm_path'")"
                        fi
  
                        # Is this something we just cloned?
                        case "$update_module" in
                        rebase)
                                command="git rebase"
 -                              die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$sm_path'")"
 -                              say_msg="$(eval_gettext "Submodule path '\$sm_path': rebased into '\$sha1'")"
 +                              die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$prefix\$sm_path'")"
 +                              say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': rebased into '\$sha1'")"
                                must_die_on_failure=yes
                                ;;
                        merge)
                                command="git merge"
 -                              die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$sm_path'")"
 -                              say_msg="$(eval_gettext "Submodule path '\$sm_path': merged in '\$sha1'")"
 +                              die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$prefix\$sm_path'")"
 +                              say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': merged in '\$sha1'")"
                                must_die_on_failure=yes
                                ;;
                        *)
                                command="git checkout $subforce -q"
 -                              die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$sm_path'")"
 -                              say_msg="$(eval_gettext "Submodule path '\$sm_path': checked out '\$sha1'")"
 +                              die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$prefix\$sm_path'")"
 +                              say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': checked out '\$sha1'")"
                                ;;
                        esac
  
  
                if test -n "$recursive"
                then
 -                      (clear_local_git_env; cd "$sm_path" && eval cmd_update "$orig_flags")
 +                      (
 +                              prefix="$prefix$sm_path/"
 +                              clear_local_git_env
 +                              cd "$sm_path" &&
 +                              eval cmd_update "$orig_flags"
 +                      )
                        res=$?
                        if test $res -gt 0
                        then
 -                              die_msg="$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
 +                              die_msg="$(eval_gettext "Failed to recurse into submodule path '\$prefix\$sm_path'")"
                                if test $res -eq 1
                                then
                                        err="${err};$die_msg"
@@@ -894,14 -837,14 +896,14 @@@ cmd_summary() 
                        for_status="$1"
                        ;;
                -n|--summary-limit)
 -                      if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
 -                      then
 -                              :
 -                      else
 -                              usage
 -                      fi
 +                      summary_limit="$2"
 +                      isnumber "$summary_limit" || usage
                        shift
                        ;;
 +              --summary-limit=*)
 +                      summary_limit="${1#--summary-limit=}"
 +                      isnumber "$summary_limit" || usage
 +                      ;;
                --)
                        shift
                        break
        done |
        if test -n "$for_status"; then
                if [ -n "$files" ]; then
 -                      gettextln "# Submodules changed but not updated:"
 +                      gettextln "Submodules changed but not updated:" | git stripspace -c
                else
 -                      gettextln "# Submodule changes to be committed:"
 +                      gettextln "Submodule changes to be committed:" | git stripspace -c
                fi
 -              echo "#"
 -              sed -e 's|^|# |' -e 's|^# $|#|'
 +              printf "\n" | git stripspace -c
 +              git stripspace -c
        else
                cat
        fi
index 5030f1f1bcc2442482ca923d03454fbc69f1a7ca,af0248d48fb2ff7b8e26047230ed988af643a483..ff265353a375d02bb578fed29ea00f07dc08a6fc
@@@ -133,7 -133,6 +133,7 @@@ test_expect_success 'submodule add --br
        (
                cd addtest &&
                git submodule add -b initial "$submodurl" submod-branch &&
 +              test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
                git submodule init
        ) &&
  
@@@ -777,18 -776,22 +777,22 @@@ test_expect_success 'submodule deinit 
        git config submodule.example.foo bar &&
        git config submodule.example2.frotz nitfol &&
        test_must_fail git submodule deinit &&
-       git submodule deinit . &&
+       git submodule deinit . >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 &&
-       git submodule deinit init example2 &&
+       git submodule deinit init example2 >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
  '
  
@@@ -798,8 -801,9 +802,9 @@@ test_expect_success 'submodule deinit f
        test_must_fail git submodule deinit init &&
        test -n "$(git config --get-regexp "submodule\.example\.")" &&
        test -f example2/.git &&
-       git submodule deinit -f init &&
+       git submodule deinit -f init >actual &&
        test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test_i18ngrep "Cleared directory .init" actual &&
        rmdir init
  '
  
@@@ -809,8 -813,9 +814,9 @@@ test_expect_success 'submodule deinit f
        test_must_fail git submodule deinit init &&
        test -n "$(git config --get-regexp "submodule\.example\.")" &&
        test -f example2/.git &&
-       git submodule deinit -f init &&
+       git submodule deinit -f init >actual &&
        test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test_i18ngrep "Cleared directory .init" actual &&
        rmdir init
  '
  
@@@ -823,8 -828,9 +829,9 @@@ test_expect_success 'submodule deinit f
        test_must_fail git submodule deinit init &&
        test -n "$(git config --get-regexp "submodule\.example\.")" &&
        test -f example2/.git &&
-       git submodule deinit -f init &&
+       git submodule deinit -f init >actual &&
        test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test_i18ngrep "Cleared directory .init" actual &&
        rmdir init
  '
  
@@@ -832,14 -838,18 +839,18 @@@ test_expect_success 'submodule deinit i
        git submodule update --init &&
        git submodule deinit init >actual &&
        test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
+       test_i18ngrep "Cleared directory .init" actual &&
        git submodule deinit init >actual &&
        test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
+       test_i18ngrep "Cleared directory .init" actual &&
        git submodule deinit . >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 &&
        git submodule deinit . >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
  '