From: Junio C Hamano Date: Fri, 5 Apr 2013 21:15:13 +0000 (-0700) Subject: Merge branch 'jl/submodule-deinit' X-Git-Tag: v1.8.3-rc0~112 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7b72ec5e14656af2d48c7a2a0b7251c35903bbaf?ds=inline;hp=-c Merge branch 'jl/submodule-deinit' A finishing touch to the new topic in 1.8.3. * jl/submodule-deinit: submodule deinit: clarify work tree removal message --- 7b72ec5e14656af2d48c7a2a0b7251c35903bbaf diff --combined git-submodule.sh index 275c664ff5,59ac86f345..79bfaac9d4 --- a/git-submodule.sh +++ b/git-submodule.sh @@@ -9,7 -9,7 +9,7 @@@ USAGE="[--quiet] add [-b ] [-f| or: $dashless [--quiet] status [--cached] [--recursive] [--] [...] or: $dashless [--quiet] init [--] [...] or: $dashless [--quiet] deinit [-f|--force] [--] ... - or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference ] [--merge] [--recursive] [--] [...] + or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference ] [--merge] [--recursive] [--] [...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] or: $dashless [--quiet] sync [--recursive] [--] [...]" @@@ -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 ;; @@@ -702,12 -665,11 +704,12 @@@ 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 @@@ -717,7 -679,7 +719,7 @@@ if test "$update_module" = "none" then - echo "Skipping submodule '$sm_path'" + echo "Skipping submodule '$prefix$sm_path'" continue fi @@@ -726,7 -688,7 +728,7 @@@ # 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 @@@ -739,21 -701,7 +741,21 @@@ 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" @@@ -772,7 -720,7 +774,7 @@@ (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? @@@ -786,20 -734,20 +788,20 @@@ 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 @@@ -817,16 -765,11 +819,16 @@@ 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 @@@ -1061,12 -1004,12 +1063,12 @@@ 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 diff --combined t/t7400-submodule-basic.sh index 5030f1f1bc,af0248d48f..ff265353a3 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@@ -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 '