summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2019-09-01 17:34:03 +0200
committerBruno Haible <bruno@clisp.org>2019-09-01 17:42:33 +0200
commit231b2a884fe695a5bc221e545440210c94f44eea (patch)
tree821d2a0d473cbee176d1c1dc0d654cf0ac190789
parent6e51f0a730a552bf5bfc912a8001738d4f23c192 (diff)
downloadgnulib-231b2a884fe695a5bc221e545440210c94f44eea.tar.gz
gnulib-231b2a884fe695a5bc221e545440210c94f44eea.tar.bz2
gitsub.sh: Add support for shallow-cloning of subdirectories.
* top/gitsub.sh (func_usage): Document allowed git options with 'git pull'. (func_pull): Accept GIT_OPTIONS argument. (pull): Parse git options before complaining about too many arguments. Pass the git options to func_pull.
-rw-r--r--ChangeLog9
-rwxr-xr-xtop/gitsub.sh40
2 files changed, 42 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 2c6939b925..fbf95966d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-09-01 Bruno Haible <bruno@clisp.org>
+
+ gitsub.sh: Add support for shallow-cloning of subdirectories.
+ * top/gitsub.sh (func_usage): Document allowed git options with
+ 'git pull'.
+ (func_pull): Accept GIT_OPTIONS argument.
+ (pull): Parse git options before complaining about too many arguments.
+ Pass the git options to func_pull.
+
2019-08-29 Bruno Haible <bruno@clisp.org>
lock: Fix cross-compilation guesses.
diff --git a/top/gitsub.sh b/top/gitsub.sh
index 9665198068..4df47fd5a8 100755
--- a/top/gitsub.sh
+++ b/top/gitsub.sh
@@ -95,13 +95,17 @@ Usage: gitsub.sh pull [SUBDIR]
Operations:
-gitsub.sh pull [SUBDIR]
+gitsub.sh pull [GIT_OPTIONS] [SUBDIR]
You should perform this operation after 'git clone ...' and after
every 'git pull'.
It brings your checkout in sync with what the other developers of
your package have committed and pushed.
If an environment variable <SUBDIR>_SRCDIR is set, with a non-empty
value, nothing is done for this SUBDIR.
+ Supported GIT_OPTIONS (for expert git users) are:
+ --reference <repository>
+ --depth <depth>
+ --recursive
If no SUBDIR is specified, the operation applies to all dependencies.
gitsub.sh upgrade [SUBDIR]
@@ -201,7 +205,8 @@ case "$1" in
echo "Try 'gitsub.sh --help' for more information." 1>&2
exit 1 ;;
esac
-if test $# = 2 && test $mode != checkout || test $# -gt 2; then
+if { test $mode = upgrade && test $# -gt 1; } \
+ || { test $mode = checkout && test $# -gt 2; }; then
echo "gitsub.sh: too many arguments in '$mode' mode" 1>&2
echo "Try 'gitsub.sh --help' for more information." 1>&2
exit 1
@@ -335,7 +340,7 @@ func_cleanup_current_git_clone ()
func_fatal_error "git clone failed"
}
-# func_pull SUBDIR
+# func_pull SUBDIR GIT_OPTIONS
# Implements the 'pull' operation.
func_pull ()
{
@@ -350,7 +355,7 @@ func_pull ()
else
# The subdir does not yet exist. Create a plain checkout.
trap func_cleanup_current_git_clone 1 2 13 15
- git clone "$url" "$path" || func_cleanup_current_git_clone
+ git clone $2 "$url" "$path" || func_cleanup_current_git_clone
trap - 1 2 13 15
fi
;;
@@ -359,7 +364,7 @@ func_pull ()
# It's a submodule.
if test -n "$needs_init"; then
# Create a submodule checkout.
- git submodule init -- "$path" && git submodule update -- "$path" || func_fatal_error "git operation failed"
+ git submodule init -- "$path" && git submodule update $2 -- "$path" || func_fatal_error "git operation failed"
else
# See https://stackoverflow.com/questions/1030169/easy-way-to-pull-latest-of-all-git-submodules
# https://stackoverflow.com/questions/4611512/is-there-a-way-to-make-git-pull-automatically-update-submodules
@@ -428,9 +433,30 @@ func_checkout ()
case "$mode" in
pull )
+ git_options=""
+ while test $# -gt 0; do
+ case "$1" in
+ --reference=* | --depth=* | --recursive)
+ git_options="$git_options $1"
+ shift
+ ;;
+ --reference | --depth)
+ git_options="$git_options $1 $2"
+ shift; shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+ if test $# -gt 1; then
+ echo "gitsub.sh: too many arguments in '$mode' mode" 1>&2
+ echo "Try 'gitsub.sh --help' for more information." 1>&2
+ exit 1
+ fi
if test $# = 0; then
for sub in $subcheckout_names $submodule_names; do
- func_pull "$sub"
+ func_pull "$sub" "$git_options"
done
else
valid=false
@@ -440,7 +466,7 @@ case "$mode" in
fi
done
if $valid; then
- func_pull "$1"
+ func_pull "$1" "$git_options"
else
func_fatal_error "Subdir '$1' is not configured as a subcheckout or a submodule in .gitmodules"
fi

Return to:

Send suggestions and report system problems to the System administrator.