From: Sven Verdoolaege Date: Fri, 04 May 2007 10:56:43 GMT Subject: [PATCH 5/5] git-clone: add --submodules for cloning submodules Message-ID: <11782762031893-git-send-email-skimo@liacs.nl> In-Reply-To: <11782762032207-git-send-email-skimo@liacs.nl> From: Sven Verdoolaege When the --submodules option is specified, git-clone will search for submodule..url options in the remote configuration and clone each submodule using the first url that it can use from the local site. The submodules are currently not checked out. Signed-off-by: Sven Verdoolaege --- Documentation/config.txt | 3 ++ Documentation/git-clone.txt | 6 +++- git-clone.sh | 68 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 24f9655..92747d8 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -597,6 +597,9 @@ showbranch.default:: The default set of branches for gitlink:git-show-branch[1]. See gitlink:git-show-branch[1]. +submodule..url + The URL of a submodule. See gitlink:git-clone[1]. + tar.umask:: By default, gitlink:git-tar-tree[1] sets file and directories modes to 0666 or 0777. While this is both useful and acceptable for projects diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index 6d32c49..b112a6a 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -11,7 +11,7 @@ SYNOPSIS [verse] 'git-clone' [--template=] [-l [-s]] [-q] [-n] [--bare] [-o ] [-u ] [--reference ] - [--depth ] [] + [--depth ] [--submodules] [] DESCRIPTION ----------- @@ -105,6 +105,10 @@ OPTIONS with a long history, and would want to send in a fixes as patches. +--submodules:: + Clone submodules specified in (remote) configuration parameters + submodule..url. + :: The (possibly remote) repository to clone from. It can be any URL git-fetch supports. diff --git a/git-clone.sh b/git-clone.sh index cad5c0c..3a9b09c 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -14,7 +14,7 @@ die() { } usage() { - die "Usage: $0 [--template=] [--reference ] [--bare] [-l [-s]] [-q] [-u ] [--origin ] [--depth ] [-n] []" + die "Usage: $0 [--template=] [--reference ] [--bare] [-l [-s]] [-q] [-u ] [--origin ] [--depth ] [-n] [--submodules] []" } get_repo_base() { @@ -67,6 +67,60 @@ Perhaps git-update-server-info needs to be run there?" rm -f "$GIT_DIR/REMOTE_HEAD" } +local_URL() { + # tranforms a "URL" on the remote to a URL that works on the local machine + # $1 - remote, $2 - URL on remote + case "$1" in + https://*|http://*|ftp://*) + case "$2" in + https://*|http://*|ftp://*) + echo $2 + esac + ;; + ssh://*) + case "$2" in + https://*|http://*|ftp://*) + echo $2 + ;; + /*) + echo $(echo $1 | sed -e 's/\(ssh:\/\/[^\/]*\)\/.*/\1/')$2 + esac + ;; + /*) + echo $2 + ;; + *) + case "$2" in + https://*|http://*|ftp://*) + echo $2 + esac + esac +} + +clone_submodules () { + # $1 - remote + previous= + git-config --remote=$1 --get-regexp 'submodule\..*\.url' | \ + sed -e 's/^submodule\.//;s/\.url / /' | + while read submodule URL + do + echo "$submodule $URL" + if test "$submodule" = "$previous" + then + continue; + fi + URL=$(local_URL "$1" "$URL") + echo "$submodule $URL" + if test -z "$URL" + then + continue; + fi + git-clone -n "$URL" "$submodule" + git-config "submodule.$submodule.url" "$URL" + previous="$submodule" + done +} + quiet= local=no use_local=no @@ -81,6 +135,7 @@ origin_override= use_separate_remote=t depth= no_progress= +submodules= test -t 1 || no_progress=--no-progress while case "$#,$1" in @@ -131,6 +186,8 @@ while *,--depth) shift depth="--depth=$1";; + *,--su|*,--sub|*,--subm|*,--submo|*,--submod|*,--submodu|*,--submodul|\ + *,--submodule|*,--submodules) submodules=yes ;; *,-*) usage ;; *) break ;; esac @@ -149,6 +206,10 @@ then then die '--bare and --origin $origin options are incompatible.' fi + if test yes = "$submodules" + then + die '--bare and --submodules origin options are incompatible.' + fi no_checkout=yes use_separate_remote= fi @@ -394,6 +455,11 @@ then git-config branch."$head_points_at".merge "refs/heads/$head_points_at" esac + if test yes = "$submodules" + then + clone_submodules "$repo" + fi + case "$no_checkout" in '') test "z$quiet" = z -a "z$no_progress" = z && v=-v || v= -- 1.5.2.rc1.25.g889f-dirty