From ca2cedba70e9356a1a20b0e39acd07ab92fee80e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 24 Apr 2009 09:06:38 +1000 Subject: git-submodule: add support for --rebase. 'git submodule update --rebase' rebases your local branch on top of what would have been checked out to a detached HEAD otherwise. In some cases, detaching the HEAD when updating a submodule complicates the workflow to commit to this submodule (checkout master, rebase, then commit). For submodules that require frequent updates but infrequent (if any) commits, a rebase can be executed directly by the git-submodule command, ensuring that the submodules stay on their respective branches. git-config key: submodule.$name.rebase (bool) Signed-off-by: Peter Hutterer Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-submodule.sh | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'git-submodule.sh') diff --git a/git-submodule.sh b/git-submodule.sh index 8e234a402..3176226ac 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -17,6 +17,7 @@ branch= quiet= cached= nofetch= +rebase= # # print stuff on stdout unless -q was specified @@ -294,6 +295,11 @@ cmd_init() git config submodule."$name".url "$url" || die "Failed to register url for submodule path '$path'" + test true != "$(git config -f .gitmodules --bool \ + submodule."$name".rebase)" || + git config submodule."$name".rebase true || + die "Failed to register submodule path '$path' as rebasing" + say "Submodule '$name' ($url) registered for path '$path'" done } @@ -321,6 +327,10 @@ cmd_update() shift nofetch=1 ;; + -r|--rebase) + shift + rebase=true + ;; --) shift break @@ -339,6 +349,7 @@ cmd_update() do name=$(module_name "$path") || exit url=$(git config submodule."$name".url) + rebase_module=$(git config --bool submodule."$name".rebase) if test -z "$url" then # Only mention uninitialized submodules when its @@ -359,6 +370,11 @@ cmd_update() die "Unable to find current revision in submodule path '$path'" fi + if test true = "$rebase" + then + rebase_module=true + fi + if test "$subsha1" != "$sha1" then force= @@ -374,11 +390,20 @@ cmd_update() 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'" + if test true = "$rebase_module" + then + command="git-rebase" + action="rebase" + msg="rebased onto" + else + command="git-checkout $force -q" + action="checkout" + msg="checked out" + fi - 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 } -- cgit v1.2.1 From 329484256e0fe42676e93669122e7a5a007ef4ed Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Wed, 3 Jun 2009 08:27:06 +0200 Subject: Rename submodule..rebase to submodule..update The addition of "submodule..rebase" demonstrates the usefulness of alternatives to the default behaviour of "git submodule update". However, by naming the config variable "submodule..rebase", and making it a boolean choice, we are artificially constraining future git versions that may want to add _more_ alternatives than just "rebase". Therefore, while "submodule..rebase" is not yet in a stable git release, future-proof it, by changing it from submodule..rebase = true/false to submodule..update = rebase/checkout where "checkout" specifies the default behaviour of "git submodule update" (checking out the new commit to a detached HEAD), and "rebase" specifies the --rebase behaviour (where the current local branch in the submodule is rebase onto the new commit). Thus .update == checkout is equivalent to .rebase == false, and .update == rebase is equivalent to .rebase == true. Finally, leaving .update unset is equivalent to leaving .rebase unset. In future git versions, other alternatives to "git submodule update" behaviour can be included by adding them to the list of allowable values for the submodule..update variable. Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- git-submodule.sh | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'git-submodule.sh') diff --git a/git-submodule.sh b/git-submodule.sh index 3176226ac..f384c6b2b 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -17,7 +17,7 @@ branch= quiet= cached= nofetch= -rebase= +update= # # print stuff on stdout unless -q was specified @@ -295,10 +295,10 @@ cmd_init() git config submodule."$name".url "$url" || die "Failed to register url for submodule path '$path'" - test true != "$(git config -f .gitmodules --bool \ - submodule."$name".rebase)" || - git config submodule."$name".rebase true || - die "Failed to register submodule path '$path' as rebasing" + 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 @@ -329,7 +329,7 @@ cmd_update() ;; -r|--rebase) shift - rebase=true + update="rebase" ;; --) shift @@ -349,7 +349,7 @@ cmd_update() do name=$(module_name "$path") || exit url=$(git config submodule."$name".url) - rebase_module=$(git config --bool submodule."$name".rebase) + update_module=$(git config submodule."$name".update) if test -z "$url" then # Only mention uninitialized submodules when its @@ -370,9 +370,9 @@ cmd_update() die "Unable to find current revision in submodule path '$path'" fi - if test true = "$rebase" + if ! test -z "$update" then - rebase_module=true + update_module=$update fi if test "$subsha1" != "$sha1" @@ -390,16 +390,18 @@ cmd_update() die "Unable to fetch in submodule path '$path'" fi - if test true = "$rebase_module" - then - command="git-rebase" + case "$update_module" in + rebase) + command="git rebase" action="rebase" msg="rebased onto" - else - command="git-checkout $force -q" + ;; + *) + command="git checkout $force -q" action="checkout" msg="checked out" - fi + ;; + esac (unset GIT_DIR; cd "$path" && $command "$sha1") || die "Unable to $action '$sha1' in submodule path '$path'" -- cgit v1.2.1