Message ID | patch-02.10-46bf600820b-20221017T115544Z-avarab@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | submodule: make it a built-in, remove git-submodule.sh | expand |
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > Remove the cmd_sync() wrapper for "git submodule--helper sync" in > favor of dispatching the raw command-line directly to the helper. > > At this point we've already parsed out the optional "--quiet" flag > that we need to support for "git submodule --quiet" (as opposed to > "git submodule <subcommand> --quiet"). For a moment, I thought this was saying that we're dropping support for "git submodule <subcommand> --quiet" in favor of "git submodule --quiet", but that's not true. Both are still supported, albeit in slightly different ways: - The subcommand "--quiet" flag is passed via $@ - The top level "--quiet" flag is parsed when we parse top level flags, which sets quiet=1, and thus passes "--quiet" to submodule--helper. We also `shift` out the "--quiet" so there's no fear of passing "--quiet" twice. Hooray!
diff --git a/git-submodule.sh b/git-submodule.sh index b851d64aa62..3fdfe864d37 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -521,39 +521,6 @@ cmd_status() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${quiet:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" } -# -# Sync remote urls for submodules -# This makes the value for remote.$remote.url match the value -# specified in .gitmodules. -# -cmd_sync() -{ - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - quiet=1 - shift - ;; - --recursive) - recursive=1 - shift - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" -} # This loop parses the command line arguments to find the # subcommand name to dispatch. Parsing of the subcommand specific @@ -607,6 +574,10 @@ case "$command" in absorbgitdirs) git submodule--helper "$command" --prefix "$wt_prefix" "$@" ;; +sync) + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ + ${quiet:+--quiet} "$@" + ;; *) "cmd_$(echo $command | sed -e s/-/_/g)" "$@" ;;
Remove the cmd_sync() wrapper for "git submodule--helper sync" in favor of dispatching the raw command-line directly to the helper. At this point we've already parsed out the optional "--quiet" flag that we need to support for "git submodule --quiet" (as opposed to "git submodule <subcommand> --quiet"). This changes the output we'll display on invalid usage for the better, before this we'd emit e.g.: $ git submodule sync --blah usage: git submodule [--quiet] [--cached] or: [...many lines of "or" usage omitted...] But now we'll emit the much more useful: $ git submodule sync --blah error: unknown option `blah' usage: git submodule sync [--quiet] [--recursive] [<path>] -q, --quiet suppress output of synchronizing submodule url --recursive recurse into nested submodules This is because we'll now get as far as module_sync()'s failing call to parse_options() when we have invalid usage. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- git-submodule.sh | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-)