summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh248
1 files changed, 53 insertions, 195 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 652861a..7f9582d 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -10,7 +10,7 @@ USAGE="[--quiet] [--cached]
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] [--[no-]single-branch] [--] [<path>...]
+ or: $dashless [--quiet] update [--init [--filter=<filter-spec>]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...]
or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path>
or: $dashless [--quiet] set-url [--] <path> <newurl>
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
@@ -30,6 +30,7 @@ GIT_PROTOCOL_FROM_USER=0
export GIT_PROTOCOL_FROM_USER
command=
+quiet=
branch=
force=
reference=
@@ -40,8 +41,9 @@ require_init=
files=
remote=
nofetch=
-update=
-prefix=
+rebase=
+merge=
+checkout=
custom_name=
depth=
progress=
@@ -49,31 +51,13 @@ dissociate=
single_branch=
jobs=
recommend_shallow=
-
-die_if_unmatched ()
-{
- if test "$1" = "#unmatched"
- then
- exit ${2:-1}
- fi
-}
+filter=
isnumber()
{
n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
}
-# Sanitize the local git environment for use within a submodule. We
-# can't simply use clear_local_git_env since we want to preserve some
-# of the settings from GIT_CONFIG_PARAMETERS.
-sanitize_submodule_env()
-{
- save_config=$GIT_CONFIG_PARAMETERS
- clear_local_git_env
- GIT_CONFIG_PARAMETERS=$save_config
- export GIT_CONFIG_PARAMETERS
-}
-
#
# Add a new submodule to the working tree, .gitmodules and the index
#
@@ -97,7 +81,7 @@ cmd_add()
force=$1
;;
-q|--quiet)
- GIT_QUIET=1
+ quiet=1
;;
--progress)
progress=1
@@ -145,7 +129,7 @@ cmd_add()
usage
fi
- git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@"
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${quiet:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@"
}
#
@@ -161,7 +145,7 @@ cmd_foreach()
do
case "$1" in
-q|--quiet)
- GIT_QUIET=1
+ quiet=1
;;
--recursive)
recursive=1
@@ -176,7 +160,7 @@ cmd_foreach()
shift
done
- git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@"
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${quiet:+--quiet} ${recursive:+--recursive} -- "$@"
}
#
@@ -191,7 +175,7 @@ cmd_init()
do
case "$1" in
-q|--quiet)
- GIT_QUIET=1
+ quiet=1
;;
--)
shift
@@ -207,7 +191,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"} submodule--helper init ${quiet:+--quiet} -- "$@"
}
#
@@ -224,7 +208,7 @@ cmd_deinit()
force=$1
;;
-q|--quiet)
- GIT_QUIET=1
+ quiet=1
;;
--all)
deinit_all=t
@@ -243,23 +227,9 @@ cmd_deinit()
shift
done
- git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@"
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${quiet:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@"
}
-# usage: fetch_in_submodule <module_path> [<depth>] [<sha1>]
-# Because arguments are positional, use an empty string to omit <depth>
-# but include <sha1>.
-fetch_in_submodule () (
- sanitize_submodule_env &&
- cd "$1" &&
- if test $# -eq 3
- then
- echo "$3" | git fetch ${GIT_QUIET:+--quiet} --stdin ${2:+"$2"}
- else
- git fetch ${GIT_QUIET:+--quiet} ${2:+"$2"}
- fi
-)
-
#
# Update each submodule path to correct revision, using clone and checkout as needed
#
@@ -272,10 +242,10 @@ cmd_update()
do
case "$1" in
-q|--quiet)
- GIT_QUIET=1
+ quiet=1
;;
- -v)
- unset GIT_QUIET
+ -v|--verbose)
+ quiet=0
;;
--progress)
progress=1
@@ -284,7 +254,6 @@ cmd_update()
init=1
;;
--require-init)
- init=1
require_init=1
;;
--remote)
@@ -297,7 +266,7 @@ cmd_update()
force=$1
;;
-r|--rebase)
- update="rebase"
+ rebase=1
;;
--reference)
case "$2" in '') usage ;; esac
@@ -311,13 +280,13 @@ cmd_update()
dissociate=1
;;
-m|--merge)
- update="merge"
+ merge=1
;;
--recursive)
recursive=1
;;
--checkout)
- update="checkout"
+ checkout=1
;;
--recommend-shallow)
recommend_shallow="--recommend-shallow"
@@ -347,6 +316,14 @@ cmd_update()
--no-single-branch)
single_branch="--no-single-branch"
;;
+ --filter)
+ case "$2" in '') usage ;; esac
+ filter="--filter=$2"
+ shift
+ ;;
+ --filter=*)
+ filter="$1"
+ ;;
--)
shift
break
@@ -361,133 +338,28 @@ cmd_update()
shift
done
- if test -n "$init"
- then
- cmd_init "--" "$@" || return
- fi
-
- {
- git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
+ ${quiet:+--quiet} \
+ ${force:+--force} \
${progress:+"--progress"} \
- ${wt_prefix:+--prefix "$wt_prefix"} \
- ${prefix:+--recursive-prefix "$prefix"} \
- ${update:+--update "$update"} \
+ ${remote:+--remote} \
+ ${recursive:+--recursive} \
+ ${init:+--init} \
+ ${nofetch:+--no-fetch} \
+ ${rebase:+--rebase} \
+ ${merge:+--merge} \
+ ${checkout:+--checkout} \
${reference:+"$reference"} \
${dissociate:+"--dissociate"} \
- ${depth:+--depth "$depth"} \
+ ${depth:+"$depth"} \
${require_init:+--require-init} \
+ ${dissociate:+"--dissociate"} \
$single_branch \
$recommend_shallow \
$jobs \
+ $filter \
-- \
- "$@" || echo "#unmatched" $?
- } | {
- err=
- while read -r quickabort sha1 just_cloned sm_path
- do
- die_if_unmatched "$quickabort" "$sha1"
-
- git submodule--helper ensure-core-worktree "$sm_path" || exit 1
-
- displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
-
- if test $just_cloned -eq 1
- then
- subsha1=
- else
- just_cloned=
- subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
- git rev-parse --verify HEAD) ||
- die "fatal: $(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
- fi
-
- if test -n "$remote"
- then
- branch=$(git submodule--helper remote-branch "$sm_path")
- if test -z "$nofetch"
- then
- # Fetch remote before determining tracking $sha1
- fetch_in_submodule "$sm_path" $depth ||
- die "fatal: $(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
- fi
- remote_name=$(sanitize_submodule_env; cd "$sm_path" && git submodule--helper print-default-remote)
- sha1=$(sanitize_submodule_env; cd "$sm_path" &&
- git rev-parse --verify "${remote_name}/${branch}") ||
- die "fatal: $(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")"
- fi
-
- out=$(git submodule--helper run-update-procedure \
- ${wt_prefix:+--prefix "$wt_prefix"} \
- ${GIT_QUIET:+--quiet} \
- ${force:+--force} \
- ${just_cloned:+--just-cloned} \
- ${nofetch:+--no-fetch} \
- ${depth:+"$depth"} \
- ${update:+--update "$update"} \
- ${prefix:+--recursive-prefix "$prefix"} \
- ${sha1:+--oid "$sha1"} \
- ${subsha1:+--suboid "$subsha1"} \
- "--" \
- "$sm_path")
-
- # exit codes for run-update-procedure:
- # 0: update was successful, say command output
- # 1: update procedure failed, but should not die
- # 2 or 128: subcommand died during execution
- # 3: no update procedure was run
- res="$?"
- case $res in
- 0)
- say "$out"
- ;;
- 1)
- err="${err};fatal: $out"
- continue
- ;;
- 2|128)
- die_with_status $res "fatal: $out"
- ;;
- esac
-
- if test -n "$recursive"
- then
- (
- prefix=$(git submodule--helper relative-path "$prefix$sm_path/" "$wt_prefix")
- wt_prefix=
- sanitize_submodule_env
- cd "$sm_path" &&
- eval cmd_update
- )
- res=$?
- if test $res -gt 0
- then
- die_msg="fatal: $(eval_gettext "Failed to recurse into submodule path '\$displaypath'")"
- if test $res -ne 2
- then
- err="${err};$die_msg"
- continue
- else
- die_with_status $res "$die_msg"
- fi
- fi
- fi
- done
-
- if test -n "$err"
- then
- OIFS=$IFS
- IFS=';'
- for e in $err
- do
- if test -n "$e"
- then
- echo >&2 "$e"
- fi
- done
- IFS=$OIFS
- exit 1
- fi
- }
+ "$@"
}
#
@@ -527,7 +399,7 @@ cmd_set_branch() {
shift
done
- git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@"
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${quiet:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@"
}
#
@@ -540,7 +412,7 @@ cmd_set_url() {
do
case "$1" in
-q|--quiet)
- GIT_QUIET=1
+ quiet=1
;;
--)
shift
@@ -556,7 +428,7 @@ cmd_set_url() {
shift
done
- git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@"
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${quiet:+--quiet} -- "$@"
}
#
@@ -577,7 +449,7 @@ cmd_summary() {
do
case "$1" in
--cached)
- cached="$1"
+ cached=1
;;
--files)
files="$1"
@@ -627,7 +499,7 @@ cmd_status()
do
case "$1" in
-q|--quiet)
- GIT_QUIET=1
+ quiet=1
;;
--cached)
cached=1
@@ -649,7 +521,7 @@ cmd_status()
shift
done
- git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@"
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${quiet:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@"
}
#
# Sync remote urls for submodules
@@ -662,7 +534,7 @@ cmd_sync()
do
case "$1" in
-q|--quiet)
- GIT_QUIET=1
+ quiet=1
shift
;;
--recursive)
@@ -682,12 +554,12 @@ cmd_sync()
esac
done
- git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@"
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${quiet:+--quiet} ${recursive:+--recursive} -- "$@"
}
cmd_absorbgitdirs()
{
- git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@"
+ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper absorbgitdirs "$@"
}
# This loop parses the command line arguments to find the
@@ -703,18 +575,10 @@ do
command=$1
;;
-q|--quiet)
- GIT_QUIET=1
- ;;
- -b|--branch)
- case "$2" in
- '')
- usage
- ;;
- esac
- branch="$2"; shift
+ quiet=1
;;
--cached)
- cached="$1"
+ cached=1
;;
--)
break
@@ -740,12 +604,6 @@ then
fi
fi
-# "-b branch" is accepted only by "add" and "set-branch"
-if test -n "$branch" && (test "$command" != add || test "$command" != set-branch)
-then
- usage
-fi
-
# "--cached" is accepted only by "status" and "summary"
if test -n "$cached" && test "$command" != status && test "$command" != summary
then