Merge branch 're/submodule-parse-opt'
"git submodule" learned various ways to spell the same option, e.g. "--branch=B" can be spelled "--branch B" or "-bB". * re/submodule-parse-opt: git-submodule.sh: rename some variables git-submodule.sh: improve variables readability git-submodule.sh: add some comments git-submodule.sh: get rid of unused variable git-submodule.sh: get rid of isnumber git-submodule.sh: improve parsing of short options git-submodule.sh: improve parsing of some long options
This commit is contained in:
216
git-submodule.sh
216
git-submodule.sh
@ -40,11 +40,11 @@ init=
|
|||||||
require_init=
|
require_init=
|
||||||
files=
|
files=
|
||||||
remote=
|
remote=
|
||||||
nofetch=
|
no_fetch=
|
||||||
rebase=
|
rebase=
|
||||||
merge=
|
merge=
|
||||||
checkout=
|
checkout=
|
||||||
custom_name=
|
name=
|
||||||
depth=
|
depth=
|
||||||
progress=
|
progress=
|
||||||
dissociate=
|
dissociate=
|
||||||
@ -52,11 +52,10 @@ single_branch=
|
|||||||
jobs=
|
jobs=
|
||||||
recommend_shallow=
|
recommend_shallow=
|
||||||
filter=
|
filter=
|
||||||
|
all=
|
||||||
isnumber()
|
default=
|
||||||
{
|
summary_limit=
|
||||||
n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
|
for_status=
|
||||||
}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Add a new submodule to the working tree, .gitmodules and the index
|
# Add a new submodule to the working tree, .gitmodules and the index
|
||||||
@ -68,31 +67,33 @@ isnumber()
|
|||||||
cmd_add()
|
cmd_add()
|
||||||
{
|
{
|
||||||
# parse $args after "submodule ... add".
|
# parse $args after "submodule ... add".
|
||||||
reference_path=
|
|
||||||
while test $# -ne 0
|
while test $# -ne 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-b | --branch)
|
-b | --branch)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
branch=$2
|
branch="--branch=$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-b* | --branch=*)
|
||||||
|
branch="$1"
|
||||||
|
;;
|
||||||
-f | --force)
|
-f | --force)
|
||||||
force=$1
|
force=$1
|
||||||
;;
|
;;
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
quiet=1
|
quiet=$1
|
||||||
;;
|
;;
|
||||||
--progress)
|
--progress)
|
||||||
progress=1
|
progress=$1
|
||||||
;;
|
;;
|
||||||
--reference)
|
--reference)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
reference_path=$2
|
reference="--reference=$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--reference=*)
|
--reference=*)
|
||||||
reference_path="${1#--reference=}"
|
reference="$1"
|
||||||
;;
|
;;
|
||||||
--ref-format)
|
--ref-format)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
@ -103,20 +104,23 @@ cmd_add()
|
|||||||
ref_format="$1"
|
ref_format="$1"
|
||||||
;;
|
;;
|
||||||
--dissociate)
|
--dissociate)
|
||||||
dissociate=1
|
dissociate=$1
|
||||||
;;
|
;;
|
||||||
--name)
|
--name)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
custom_name=$2
|
name="--name=$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--name=*)
|
||||||
|
name="$1"
|
||||||
|
;;
|
||||||
--depth)
|
--depth)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
depth="--depth=$2"
|
depth="--depth=$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--depth=*)
|
--depth=*)
|
||||||
depth=$1
|
depth="$1"
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
@ -138,14 +142,14 @@ cmd_add()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add \
|
||||||
${quiet:+--quiet} \
|
$quiet \
|
||||||
${force:+--force} \
|
$force \
|
||||||
${progress:+"--progress"} \
|
$progress \
|
||||||
${branch:+--branch "$branch"} \
|
${branch:+"$branch"} \
|
||||||
${reference_path:+--reference "$reference_path"} \
|
${reference:+"$reference"} \
|
||||||
${ref_format:+"$ref_format"} \
|
${ref_format:+"$ref_format"} \
|
||||||
${dissociate:+--dissociate} \
|
$dissociate \
|
||||||
${custom_name:+--name "$custom_name"} \
|
${name:+"$name"} \
|
||||||
${depth:+"$depth"} \
|
${depth:+"$depth"} \
|
||||||
-- \
|
-- \
|
||||||
"$@"
|
"$@"
|
||||||
@ -164,10 +168,10 @@ cmd_foreach()
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
quiet=1
|
quiet=$1
|
||||||
;;
|
;;
|
||||||
--recursive)
|
--recursive)
|
||||||
recursive=1
|
recursive=$1
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage
|
usage
|
||||||
@ -180,8 +184,8 @@ cmd_foreach()
|
|||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach \
|
||||||
${quiet:+--quiet} \
|
$quiet \
|
||||||
${recursive:+--recursive} \
|
$recursive \
|
||||||
-- \
|
-- \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
@ -198,7 +202,7 @@ cmd_init()
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
quiet=1
|
quiet=$1
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
@ -215,7 +219,7 @@ cmd_init()
|
|||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init \
|
||||||
${quiet:+--quiet} \
|
$quiet \
|
||||||
-- \
|
-- \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
@ -226,7 +230,6 @@ cmd_init()
|
|||||||
cmd_deinit()
|
cmd_deinit()
|
||||||
{
|
{
|
||||||
# parse $args after "submodule ... deinit".
|
# parse $args after "submodule ... deinit".
|
||||||
deinit_all=
|
|
||||||
while test $# -ne 0
|
while test $# -ne 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -234,10 +237,10 @@ cmd_deinit()
|
|||||||
force=$1
|
force=$1
|
||||||
;;
|
;;
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
quiet=1
|
quiet=$1
|
||||||
;;
|
;;
|
||||||
--all)
|
--all)
|
||||||
deinit_all=t
|
all=$1
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
@ -254,9 +257,9 @@ cmd_deinit()
|
|||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit \
|
||||||
${quiet:+--quiet} \
|
$quiet \
|
||||||
${force:+--force} \
|
$force \
|
||||||
${deinit_all:+--all} \
|
$all \
|
||||||
-- \
|
-- \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
@ -273,31 +276,31 @@ cmd_update()
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
quiet=1
|
quiet=$1
|
||||||
;;
|
;;
|
||||||
-v|--verbose)
|
-v|--verbose)
|
||||||
quiet=0
|
quiet=
|
||||||
;;
|
;;
|
||||||
--progress)
|
--progress)
|
||||||
progress=1
|
progress=$1
|
||||||
;;
|
;;
|
||||||
-i|--init)
|
-i|--init)
|
||||||
init=1
|
init=$1
|
||||||
;;
|
;;
|
||||||
--require-init)
|
--require-init)
|
||||||
require_init=1
|
require_init=$1
|
||||||
;;
|
;;
|
||||||
--remote)
|
--remote)
|
||||||
remote=1
|
remote=$1
|
||||||
;;
|
;;
|
||||||
-N|--no-fetch)
|
-N|--no-fetch)
|
||||||
nofetch=1
|
no_fetch=$1
|
||||||
;;
|
;;
|
||||||
-f|--force)
|
-f|--force)
|
||||||
force=$1
|
force=$1
|
||||||
;;
|
;;
|
||||||
-r|--rebase)
|
-r|--rebase)
|
||||||
rebase=1
|
rebase=$1
|
||||||
;;
|
;;
|
||||||
--ref-format)
|
--ref-format)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
@ -316,22 +319,19 @@ cmd_update()
|
|||||||
reference="$1"
|
reference="$1"
|
||||||
;;
|
;;
|
||||||
--dissociate)
|
--dissociate)
|
||||||
dissociate=1
|
dissociate=$1
|
||||||
;;
|
;;
|
||||||
-m|--merge)
|
-m|--merge)
|
||||||
merge=1
|
merge=$1
|
||||||
;;
|
;;
|
||||||
--recursive)
|
--recursive)
|
||||||
recursive=1
|
recursive=$1
|
||||||
;;
|
;;
|
||||||
--checkout)
|
--checkout)
|
||||||
checkout=1
|
checkout=$1
|
||||||
;;
|
;;
|
||||||
--recommend-shallow)
|
--recommend-shallow|--no-recommend-shallow)
|
||||||
recommend_shallow="--recommend-shallow"
|
recommend_shallow=$1
|
||||||
;;
|
|
||||||
--no-recommend-shallow)
|
|
||||||
recommend_shallow="--no-recommend-shallow"
|
|
||||||
;;
|
;;
|
||||||
--depth)
|
--depth)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
@ -339,21 +339,18 @@ cmd_update()
|
|||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--depth=*)
|
--depth=*)
|
||||||
depth=$1
|
depth="$1"
|
||||||
;;
|
;;
|
||||||
-j|--jobs)
|
-j|--jobs)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
jobs="--jobs=$2"
|
jobs="--jobs=$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--jobs=*)
|
-j*|--jobs=*)
|
||||||
jobs=$1
|
jobs="$1"
|
||||||
;;
|
;;
|
||||||
--single-branch)
|
--single-branch|--no-single-branch)
|
||||||
single_branch="--single-branch"
|
single_branch=$1
|
||||||
;;
|
|
||||||
--no-single-branch)
|
|
||||||
single_branch="--no-single-branch"
|
|
||||||
;;
|
;;
|
||||||
--filter)
|
--filter)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
@ -378,22 +375,21 @@ cmd_update()
|
|||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
|
||||||
${quiet:+--quiet} \
|
$quiet \
|
||||||
${force:+--force} \
|
$force \
|
||||||
${progress:+"--progress"} \
|
$progress \
|
||||||
${remote:+--remote} \
|
$remote \
|
||||||
${recursive:+--recursive} \
|
$recursive \
|
||||||
${init:+--init} \
|
$init \
|
||||||
${nofetch:+--no-fetch} \
|
$no_fetch \
|
||||||
${rebase:+--rebase} \
|
$rebase \
|
||||||
${merge:+--merge} \
|
$merge \
|
||||||
${checkout:+--checkout} \
|
$checkout \
|
||||||
${ref_format:+"$ref_format"} \
|
${ref_format:+"$ref_format"} \
|
||||||
${reference:+"$reference"} \
|
${reference:+"$reference"} \
|
||||||
${dissociate:+"--dissociate"} \
|
$dissociate \
|
||||||
${depth:+"$depth"} \
|
${depth:+"$depth"} \
|
||||||
${require_init:+--require-init} \
|
$require_init \
|
||||||
${dissociate:+"--dissociate"} \
|
|
||||||
$single_branch \
|
$single_branch \
|
||||||
$recommend_shallow \
|
$recommend_shallow \
|
||||||
$jobs \
|
$jobs \
|
||||||
@ -408,9 +404,7 @@ cmd_update()
|
|||||||
# $@ = requested path
|
# $@ = requested path
|
||||||
#
|
#
|
||||||
cmd_set_branch() {
|
cmd_set_branch() {
|
||||||
default=
|
# parse $args after "submodule ... set-branch".
|
||||||
branch=
|
|
||||||
|
|
||||||
while test $# -ne 0
|
while test $# -ne 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -418,13 +412,16 @@ cmd_set_branch() {
|
|||||||
# we don't do anything with this but we need to accept it
|
# we don't do anything with this but we need to accept it
|
||||||
;;
|
;;
|
||||||
-d|--default)
|
-d|--default)
|
||||||
default=1
|
default=$1
|
||||||
;;
|
;;
|
||||||
-b|--branch)
|
-b|--branch)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
branch=$2
|
branch="--branch=$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-b*|--branch=*)
|
||||||
|
branch="$1"
|
||||||
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break
|
break
|
||||||
@ -440,9 +437,9 @@ cmd_set_branch() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch \
|
||||||
${quiet:+--quiet} \
|
$quiet \
|
||||||
${branch:+--branch "$branch"} \
|
${branch:+"$branch"} \
|
||||||
${default:+--default} \
|
$default \
|
||||||
-- \
|
-- \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
@ -453,11 +450,12 @@ cmd_set_branch() {
|
|||||||
# $@ = requested path, requested url
|
# $@ = requested path, requested url
|
||||||
#
|
#
|
||||||
cmd_set_url() {
|
cmd_set_url() {
|
||||||
|
# parse $args after "submodule ... set-url".
|
||||||
while test $# -ne 0
|
while test $# -ne 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
quiet=1
|
quiet=$1
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
@ -474,7 +472,7 @@ cmd_set_url() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url \
|
||||||
${quiet:+--quiet} \
|
$quiet \
|
||||||
-- \
|
-- \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
@ -488,31 +486,26 @@ cmd_set_url() {
|
|||||||
# $@ = [commit (default 'HEAD'),] requested paths (default all)
|
# $@ = [commit (default 'HEAD'),] requested paths (default all)
|
||||||
#
|
#
|
||||||
cmd_summary() {
|
cmd_summary() {
|
||||||
summary_limit=-1
|
|
||||||
for_status=
|
|
||||||
diff_cmd=diff-index
|
|
||||||
|
|
||||||
# parse $args after "submodule ... summary".
|
# parse $args after "submodule ... summary".
|
||||||
while test $# -ne 0
|
while test $# -ne 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--cached)
|
--cached)
|
||||||
cached=1
|
cached=$1
|
||||||
;;
|
;;
|
||||||
--files)
|
--files)
|
||||||
files="$1"
|
files=$1
|
||||||
;;
|
;;
|
||||||
--for-status)
|
--for-status)
|
||||||
for_status="$1"
|
for_status=$1
|
||||||
;;
|
;;
|
||||||
-n|--summary-limit)
|
-n|--summary-limit)
|
||||||
summary_limit="$2"
|
case "$2" in '') usage ;; esac
|
||||||
isnumber "$summary_limit" || usage
|
summary_limit="--summary-limit=$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--summary-limit=*)
|
-n*|--summary-limit=*)
|
||||||
summary_limit="${1#--summary-limit=}"
|
summary_limit="$1"
|
||||||
isnumber "$summary_limit" || usage
|
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
@ -529,10 +522,10 @@ cmd_summary() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary \
|
||||||
${files:+--files} \
|
$files \
|
||||||
${cached:+--cached} \
|
$cached \
|
||||||
${for_status:+--for-status} \
|
$for_status \
|
||||||
${summary_limit:+-n $summary_limit} \
|
${summary_limit:+"$summary_limit"} \
|
||||||
-- \
|
-- \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
@ -553,13 +546,13 @@ cmd_status()
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
quiet=1
|
quiet=$1
|
||||||
;;
|
;;
|
||||||
--cached)
|
--cached)
|
||||||
cached=1
|
cached=$1
|
||||||
;;
|
;;
|
||||||
--recursive)
|
--recursive)
|
||||||
recursive=1
|
recursive=$1
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
@ -576,9 +569,9 @@ cmd_status()
|
|||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status \
|
||||||
${quiet:+--quiet} \
|
$quiet \
|
||||||
${cached:+--cached} \
|
$cached \
|
||||||
${recursive:+--recursive} \
|
$recursive \
|
||||||
-- \
|
-- \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
@ -590,15 +583,16 @@ cmd_status()
|
|||||||
#
|
#
|
||||||
cmd_sync()
|
cmd_sync()
|
||||||
{
|
{
|
||||||
|
# parse $args after "submodule ... sync".
|
||||||
while test $# -ne 0
|
while test $# -ne 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
quiet=1
|
quiet=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--recursive)
|
--recursive)
|
||||||
recursive=1
|
recursive=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
@ -615,8 +609,8 @@ cmd_sync()
|
|||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync \
|
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync \
|
||||||
${quiet:+--quiet} \
|
$quiet \
|
||||||
${recursive:+--recursive} \
|
$recursive \
|
||||||
-- \
|
-- \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
@ -639,10 +633,10 @@ do
|
|||||||
command=$1
|
command=$1
|
||||||
;;
|
;;
|
||||||
-q|--quiet)
|
-q|--quiet)
|
||||||
quiet=1
|
quiet=$1
|
||||||
;;
|
;;
|
||||||
--cached)
|
--cached)
|
||||||
cached=1
|
cached=$1
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
break
|
break
|
||||||
|
Reference in New Issue
Block a user