From: Junio C Hamano Date: Thu, 25 Apr 2019 07:41:24 +0000 (+0900) Subject: Merge branch 'nd/submodule-foreach-quiet' X-Git-Tag: v2.22.0-rc0~39 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f1c9f6ce38445c7cba7dd5b2a8c329c8fff90993?ds=inline;hp=-c Merge branch 'nd/submodule-foreach-quiet' "git submodule foreach --quiet" did not pass the option down correctly, which has been corrected. * nd/submodule-foreach-quiet: submodule foreach: fix " --quiet" not being respected --- f1c9f6ce38445c7cba7dd5b2a8c329c8fff90993 diff --combined builtin/submodule--helper.c index 168be97ffb,c934c21e3d..8c72ea864c --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@@ -348,7 -348,7 +348,7 @@@ static int module_list_compute(int argc i++; } - if (ps_matched && report_path_error(ps_matched, pathspec, prefix)) + if (ps_matched && report_path_error(ps_matched, pathspec)) result = -1; free(ps_matched); @@@ -566,12 -566,12 +566,12 @@@ static int module_foreach(int argc, con }; const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper foreach [--quiet] [--recursive] "), + N_("git submodule--helper foreach [--quiet] [--recursive] [--] "), NULL }; argc = parse_options(argc, argv, prefix, module_foreach_options, - git_submodule_helper_usage, PARSE_OPT_KEEP_UNKNOWN); + git_submodule_helper_usage, 0); if (module_list_compute(0, NULL, prefix, &pathspec, &list) < 0) return 1; @@@ -709,7 -709,7 +709,7 @@@ static int module_init(int argc, const }; const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper init []"), + N_("git submodule--helper init [] []"), NULL }; @@@ -1816,10 -1816,11 +1816,10 @@@ static int update_submodules(struct sub { int i; - run_processes_parallel(suc->max_jobs, - update_clone_get_next_task, - update_clone_start_failure, - update_clone_task_finished, - suc); + run_processes_parallel_tr2(suc->max_jobs, update_clone_get_next_task, + update_clone_start_failure, + update_clone_task_finished, suc, "submodule", + "parallel/update"); /* * We saved the output and put it out all at once now. @@@ -2096,7 -2097,7 +2096,7 @@@ static int absorb_git_dirs(int argc, co }; const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper embed-git-dir [...]"), + N_("git submodule--helper absorb-git-dirs [] [...]"), NULL }; @@@ -2147,22 -2148,17 +2147,22 @@@ static int check_name(int argc, const c static int module_config(int argc, const char **argv, const char *prefix) { enum { - CHECK_WRITEABLE = 1 + CHECK_WRITEABLE = 1, + DO_UNSET = 2 } command = 0; struct option module_config_options[] = { OPT_CMDMODE(0, "check-writeable", &command, N_("check if it is safe to write to the .gitmodules file"), CHECK_WRITEABLE), + OPT_CMDMODE(0, "unset", &command, + N_("unset the config in the .gitmodules file"), + DO_UNSET), OPT_END() }; const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper config name [value]"), + N_("git submodule--helper config []"), + N_("git submodule--helper config --unset "), N_("git submodule--helper config --check-writeable"), NULL }; @@@ -2174,17 -2170,15 +2174,17 @@@ return is_writing_gitmodules_ok() ? 0 : -1; /* Equivalent to ACTION_GET in builtin/config.c */ - if (argc == 2) + if (argc == 2 && command != DO_UNSET) return print_config_from_gitmodules(the_repository, argv[1]); /* Equivalent to ACTION_SET in builtin/config.c */ - if (argc == 3) { + if (argc == 3 || (argc == 2 && command == DO_UNSET)) { + const char *value = (argc == 3) ? argv[2] : NULL; + if (!is_writing_gitmodules_ok()) die(_("please make sure that the .gitmodules file is in the working tree")); - return config_set_in_gitmodules_file_gently(argv[1], argv[2]); + return config_set_in_gitmodules_file_gently(argv[1], value); } usage_with_options(git_submodule_helper_usage, module_config_options); diff --combined git-submodule.sh index 99fba417b1,d7edd25dc3..e3c054bde5 --- a/git-submodule.sh +++ b/git-submodule.sh @@@ -5,13 -5,11 +5,13 @@@ # Copyright (c) 2007 Lars Hjemli dashless=$(basename "$0" | sed -e 's/-/ /') -USAGE="[--quiet] add [-b ] [-f|--force] [--name ] [--reference ] [--] [] +USAGE="[--quiet] [--cached] + or: $dashless [--quiet] add [-b ] [-f|--force] [--name ] [--reference ] [--] [] or: $dashless [--quiet] status [--cached] [--recursive] [--] [...] or: $dashless [--quiet] init [--] [...] or: $dashless [--quiet] deinit [-f|--force] (--all| [--] ...) or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference ] [--recursive] [--] [...] + or: $dashless [--quiet] set-branch (--default|--branch ) [--] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] or: $dashless [--quiet] sync [--recursive] [--] [...] @@@ -347,7 -345,7 +347,7 @@@ cmd_foreach( shift done - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} "$@" + git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" } # @@@ -378,7 -376,7 +378,7 @@@ cmd_init( shift done - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} "$@" + git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" } # @@@ -414,7 -412,7 +414,7 @@@ cmd_deinit( shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${prefix:+--prefix "$prefix"} ${force:+--force} ${deinit_all:+--all} "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${prefix:+--prefix "$prefix"} ${force:+--force} ${deinit_all:+--all} -- "$@" } is_tip_reachable () ( @@@ -543,6 -541,7 +543,7 @@@ cmd_update( ${depth:+--depth "$depth"} \ $recommend_shallow \ $jobs \ + -- \ "$@" || echo "#unmatched" $? } | { err= @@@ -595,7 -594,7 +596,7 @@@ # is not reachable from a ref. is_tip_reachable "$sm_path" "$sha1" || fetch_in_submodule "$sm_path" $depth || - say "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")" + say "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'; trying to directly fetch \$sha1:")" # Now we tried the usual fetch, but $sha1 may # not be reachable from any of the refs @@@ -686,72 -685,6 +687,72 @@@ } } +# +# Configures a submodule's default branch +# +# $@ = requested path +# +cmd_set_branch() { + unset_branch=false + branch= + + while test $# -ne 0 + do + case "$1" in + -q|--quiet) + # we don't do anything with this but we need to accept it + ;; + -d|--default) + unset_branch=true + ;; + -b|--branch) + case "$2" in '') usage ;; esac + branch=$2 + shift + ;; + --) + shift + break + ;; + -*) + usage + ;; + *) + break + ;; + esac + shift + done + + if test $# -ne 1 + then + usage + fi + + # we can't use `git submodule--helper name` here because internally, it + # hashes the path so a trailing slash could lead to an unintentional no match + name="$(git submodule--helper list "$1" | cut -f2)" + if test -z "$name" + then + exit 1 + fi + + test -n "$branch"; has_branch=$? + test "$unset_branch" = true; has_unset_branch=$? + + if test $((!$has_branch != !$has_unset_branch)) -eq 0 + then + usage + fi + + if test $has_branch -eq 0 + then + git submodule--helper config submodule."$name".branch "$branch" + else + git submodule--helper config --unset submodule."$name".branch + fi +} + # # Show commit summary for submodules in index or working tree # @@@ -1001,7 -934,7 +1002,7 @@@ cmd_status( shift done - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} "$@" + git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" } # # Sync remote urls for submodules @@@ -1034,7 -967,7 +1035,7 @@@ cmd_sync( esac done - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} "$@" + git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" } cmd_absorbgitdirs() @@@ -1051,7 -984,7 +1052,7 @@@ while test $# != 0 && test -z "$command" do case "$1" in - add | foreach | init | deinit | update | status | summary | sync | absorbgitdirs) + add | foreach | init | deinit | update | set-branch | status | summary | sync | absorbgitdirs) command=$1 ;; -q|--quiet) @@@ -1092,8 -1025,8 +1093,8 @@@ the fi fi -# "-b branch" is accepted only by "add" -if test -n "$branch" && test "$command" != add +# "-b branch" is accepted only by "add" and "set-branch" +if test -n "$branch" && (test "$command" != add || test "$command" != set-branch) then usage fi @@@ -1104,4 -1037,4 +1105,4 @@@ the usage fi -"cmd_$command" "$@" +"cmd_$(echo $command | sed -e s/-/_/g)" "$@"