From: Junio C Hamano Date: Sat, 13 Jun 2009 19:49:50 +0000 (-0700) Subject: Merge branch 'ph/submodule-rebase' (early part) X-Git-Tag: v1.6.4-rc0~65 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7d40f89137b456820d51ebc1cbb3ffbb966e7fec?ds=inline;hp=-c Merge branch 'ph/submodule-rebase' (early part) * 'ph/submodule-rebase' (early part): Rename submodule..rebase to submodule..update git-submodule: add support for --rebase. Conflicts: Documentation/git-submodule.txt git-submodule.sh --- 7d40f89137b456820d51ebc1cbb3ffbb966e7fec diff --combined Documentation/git-submodule.txt index 14256c695b,f993469dc6..cd8e861ce4 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@@ -9,12 -9,10 +9,12 @@@ git-submodule - Initialize, update or i SYNOPSIS -------- [verse] -'git submodule' [--quiet] add [-b branch] [--] +'git submodule' [--quiet] add [-b branch] + [--reference ] [--] 'git submodule' [--quiet] status [--cached] [--] [...] 'git submodule' [--quiet] init [--] [...] - 'git submodule' [--quiet] update [--init] [-N|--no-fetch] -'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--] [...] ++'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase] + [--reference ] [--] [...] 'git submodule' [--quiet] summary [--summary-limit ] [commit] [--] [...] 'git submodule' [--quiet] foreach 'git submodule' [--quiet] sync [--] [...] @@@ -115,7 -113,8 +115,8 @@@ init: update:: Update the registered submodules, i.e. clone missing submodules and checkout the commit specified in the index of the containing repository. - This will make the submodules HEAD be detached. + This will make the submodules HEAD be detached unless '--rebase' is + specified or the key `submodule.$name.update` is set to `rebase`. + If the submodule is not yet initialized, and you just want to use the setting as stored in .gitmodules, you can automatically initialize the @@@ -179,14 -178,15 +180,23 @@@ OPTION This option is only valid for the update command. Don't fetch new objects from the remote site. + --rebase:: + This option is only valid for the update command. + Rebase the current branch onto the commit recorded in the + superproject. If this option is given, the submodule's HEAD will not + be detached. If a a merge failure prevents this process, you will have + to resolve these failures with linkgit:git-rebase[1]. + If the key `submodule.$name.update` is set to `rebase`, this option is + implicit. + +--reference :: + This option is only valid for add and update commands. These + commands sometimes need to clone a remote repository. In this case, + this option will be passed to the linkgit:git-clone[1] command. ++ +*NOTE*: Do *not* use this option unless you have read the note +for linkgit:git-clone[1]'s --reference and --shared options carefully. + ...:: Paths to submodule(s). When specified this will restrict the command to only operate on the submodules found at the specified paths. diff --combined git-submodule.sh index ab1ed02a66,f384c6b2b4..19a3a840fd --- a/git-submodule.sh +++ b/git-submodule.sh @@@ -15,9 -15,9 +15,10 @@@ require_work_tre command= branch= quiet= +reference= cached= nofetch= + update= # # print stuff on stdout unless -q was specified @@@ -92,7 -92,6 +93,7 @@@ module_clone( { path=$1 url=$2 + reference="$3" # If there already is a directory at the submodule path, # expect it to be empty (since that is the default checkout @@@ -108,12 -107,7 +109,12 @@@ test -e "$path" && die "A file already exist at path '$path'" - git-clone -n "$url" "$path" || + if test -n "$reference" + then + git-clone "$reference" -n "$url" "$path" + else + git-clone -n "$url" "$path" + fi || die "Clone of '$url' into submodule path '$path' failed" } @@@ -138,15 -132,6 +139,15 @@@ cmd_add( -q|--quiet) quiet=1 ;; + --reference) + case "$2" in '') usage ;; esac + reference="--reference=$2" + shift + ;; + --reference=*) + reference="$1" + shift + ;; --) shift break @@@ -219,7 -204,7 +220,7 @@@ git config submodule."$path".url "$url" else - module_clone "$path" "$realrepo" || exit + module_clone "$path" "$realrepo" "$reference" || exit ( unset GIT_DIR cd "$path" && @@@ -310,6 -295,11 +311,11 @@@ cmd_init( git config submodule."$name".url "$url" || die "Failed to register url for submodule path '$path'" + upd="$(git config -f .gitmodules submodule."$name".update)" + test -z "$upd" || + git config submodule."$name".update "$upd" || + die "Failed to register update mode for submodule path '$path'" + say "Submodule '$name' ($url) registered for path '$path'" done } @@@ -330,22 -320,17 +336,26 @@@ cmd_update( quiet=1 ;; -i|--init) + init=1 shift - cmd_init "$@" || return ;; -N|--no-fetch) shift nofetch=1 ;; + -r|--rebase) + shift + update="rebase" + ;; + --reference) + case "$2" in '') usage ;; esac + reference="--reference=$2" + shift 2 + ;; + --reference=*) + reference="$1" + shift + ;; --) shift break @@@ -359,16 -344,12 +369,17 @@@ esac done + if test -n "$init" + then + cmd_init "--" "$@" || return + fi + module_list "$@" | while read mode sha1 stage path do name=$(module_name "$path") || exit url=$(git config submodule."$name".url) + update_module=$(git config submodule."$name".update) if test -z "$url" then # Only mention uninitialized submodules when its @@@ -381,7 -362,7 +392,7 @@@ if ! test -d "$path"/.git -o -f "$path"/.git then - module_clone "$path" "$url" || exit + module_clone "$path" "$url" "$reference"|| exit subsha1= else subsha1=$(unset GIT_DIR; cd "$path" && @@@ -389,6 -370,11 +400,11 @@@ die "Unable to find current revision in submodule path '$path'" fi + if ! test -z "$update" + then + update_module=$update + fi + if test "$subsha1" != "$sha1" then force= @@@ -404,11 -390,22 +420,22 @@@ die "Unable to fetch in submodule path '$path'" fi - (unset GIT_DIR; cd "$path" && - git-checkout $force -q "$sha1") || - die "Unable to checkout '$sha1' in submodule path '$path'" + case "$update_module" in + rebase) + command="git rebase" + action="rebase" + msg="rebased onto" + ;; + *) + command="git checkout $force -q" + action="checkout" + msg="checked out" + ;; + esac - say "Submodule path '$path': checked out '$sha1'" + (unset GIT_DIR; cd "$path" && $command "$sha1") || + die "Unable to $action '$sha1' in submodule path '$path'" + say "Submodule path '$path': $msg '$sha1'" fi done }