Merge branch 'nd/submodule-foreach-quiet'
authorJunio C Hamano <gitster@pobox.com>
Thu, 25 Apr 2019 07:41:24 +0000 (16:41 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Apr 2019 07:41:24 +0000 (16:41 +0900)
"git submodule foreach <command> --quiet" did not pass the option
down correctly, which has been corrected.

* nd/submodule-foreach-quiet:
submodule foreach: fix "<command> --quiet" not being respected

1  2 
builtin/submodule--helper.c
git-submodule.sh
index 168be97ffba6c7691531811893130160d060c984,c934c21e3d0128138d1c16d689b0611ad3e81142..8c72ea864c81d8763ac48ee7e1e7795e1323ddb3
@@@ -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] <command>"),
+               N_("git submodule--helper foreach [--quiet] [--recursive] [--] <command>"),
                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 [<path>]"),
+               N_("git submodule--helper init [<options>] [<path>]"),
                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 [<path>...]"),
+               N_("git submodule--helper absorb-git-dirs [<options>] [<path>...]"),
                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 <name> [<value>]"),
 +              N_("git submodule--helper config --unset <name>"),
                N_("git submodule--helper config --check-writeable"),
                NULL
        };
                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 99fba417b1e742e70f6ff8ccb31b58ee181bc4f7,d7edd25dc3beb8e3acddb4f30d622d7222701001..e3c054bde5f1d6fb858071ba7bf2939253811e1f
@@@ -5,13 -5,11 +5,13 @@@
  # Copyright (c) 2007 Lars Hjemli
  
  dashless=$(basename "$0" | sed -e 's/-/ /')
 -USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
 +USAGE="[--quiet] [--cached]
 +   or: $dashless [--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] (--all| [--] <path>...)
     or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
 +   or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path>
     or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
     or: $dashless [--quiet] foreach [--recursive] <command>
     or: $dashless [--quiet] sync [--recursive] [--] [<path>...]
@@@ -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=
                                # 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
        }
  }
  
 +#
 +# 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()
  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)" "$@"