提交 5c08dbbd 编写于 作者: J Junio C Hamano

git-submodule: fix subcommand parser

The subcommand parser of "git submodule" made its subcommand
names reserved words.  As a consequence, a command like this:

    $ git submodule add init update

which is meant to add a submodule called 'init' at path 'update'
was misinterpreted as a request to invoke more than one mutually
incompatible subcommands and incorrectly rejected.

This patch fixes the issue by stopping the subcommand parsing at
the first subcommand word, to allow the sample command line
above to work as expected.

It also introduces the usual -- option disambiguator, so that a
submodule at path '-foo' can be updated with

    $ git submodule update -- -foo

without triggering an "unrecognized option -foo" error.
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 23a485e3
...@@ -9,11 +9,8 @@ OPTIONS_SPEC= ...@@ -9,11 +9,8 @@ OPTIONS_SPEC=
. git-sh-setup . git-sh-setup
require_work_tree require_work_tree
add= command=
branch= branch=
init=
update=
status=
quiet= quiet=
cached= cached=
...@@ -123,6 +120,32 @@ module_clone() ...@@ -123,6 +120,32 @@ module_clone()
# #
cmd_add() cmd_add()
{ {
# parse $args after "submodule ... add".
while test $# -ne 0
do
case "$1" in
-b | --branch)
case "$2" in '') usage ;; esac
branch=$2
shift
;;
-q|--quiet)
quiet=1
;;
--)
shift
break
;;
-*)
usage
;;
*)
break
;;
esac
shift
done
repo=$1 repo=$1
path=$2 path=$2
...@@ -176,6 +199,27 @@ cmd_add() ...@@ -176,6 +199,27 @@ cmd_add()
# #
cmd_init() cmd_init()
{ {
# parse $args after "submodule ... init".
while test $# -ne 0
do
case "$1" in
-q|--quiet)
quiet=1
;;
--)
shift
break
;;
-*)
usage
;;
*)
break
;;
esac
shift
done
git ls-files --stage -- "$@" | grep -e '^160000 ' | git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path while read mode sha1 stage path
do do
...@@ -209,6 +253,27 @@ cmd_init() ...@@ -209,6 +253,27 @@ cmd_init()
# #
cmd_update() cmd_update()
{ {
# parse $args after "submodule ... update".
while test $# -ne 0
do
case "$1" in
-q|--quiet)
quiet=1
;;
--)
shift
break
;;
-*)
usage
;;
*)
break
;;
esac
shift
done
git ls-files --stage -- "$@" | grep -e '^160000 ' | git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path while read mode sha1 stage path
do do
...@@ -268,6 +333,30 @@ set_name_rev () { ...@@ -268,6 +333,30 @@ set_name_rev () {
# #
cmd_status() cmd_status()
{ {
# parse $args after "submodule ... status".
while test $# -ne 0
do
case "$1" in
-q|--quiet)
quiet=1
;;
--cached)
cached=1
;;
--)
shift
break
;;
-*)
usage
;;
*)
break
;;
esac
shift
done
git ls-files --stage -- "$@" | grep -e '^160000 ' | git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path while read mode sha1 stage path
do do
...@@ -293,20 +382,17 @@ cmd_status() ...@@ -293,20 +382,17 @@ cmd_status()
done done
} }
while test $# != 0 # This loop parses the command line arguments to find the
# subcommand name to dispatch. Parsing of the subcommand specific
# options are primarily done by the subcommand implementations.
# Subcommand specific options such as --branch and --cached are
# parsed here as well, for backward compatibility.
while test $# != 0 && test -z "$command"
do do
case "$1" in case "$1" in
add) add | init | update | status)
add=1 command=$1
;;
init)
init=1
;;
update)
update=1
;;
status)
status=1
;; ;;
-q|--quiet) -q|--quiet)
quiet=1 quiet=1
...@@ -335,30 +421,19 @@ do ...@@ -335,30 +421,19 @@ do
shift shift
done done
case "$add,$branch" in # No command word defaults to "status"
1,*) test -n "$command" || command=status
;;
,) # "-b branch" is accepted only by "add"
;; if test -n "$branch" && test "$command" != add
,*) then
usage usage
;; fi
esac
# "--cached" is accepted only by "status"
case "$add,$init,$update,$status,$cached" in if test -n "$cached" && test "$command" != status
1,,,,) then
cmd_add "$@"
;;
,1,,,)
cmd_init "$@"
;;
,,1,,)
cmd_update "$@"
;;
,,,*,*)
cmd_status "$@"
;;
*)
usage usage
;; fi
esac
"cmd_$command" "$@"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册