submodule, repack: migrate to git-sh-setup's say()
[gitweb.git] / git-submodule.sh
index 3176226ac7ecca9dc875a20bd5c2df607cdfb504..58d2fd2ccb65925e81b1aab3c8e624359b286a14 100755 (executable)
@@ -14,21 +14,10 @@ require_work_tree
 
 command=
 branch=
-quiet=
+reference=
 cached=
 nofetch=
-rebase=
-
-#
-# print stuff on stdout unless -q was specified
-#
-say()
-{
-       if test -z "$quiet"
-       then
-               echo "$@"
-       fi
-}
+update=
 
 # Resolve relative url by appending to parent's url
 resolve_relative_url ()
@@ -92,6 +81,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
@@ -107,7 +97,12 @@ module_clone()
        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"
 }
 
@@ -130,7 +125,16 @@ cmd_add()
                        shift
                        ;;
                -q|--quiet)
-                       quiet=1
+                       GIT_QUIET=1
+                       ;;
+               --reference)
+                       case "$2" in '') usage ;; esac
+                       reference="--reference=$2"
+                       shift
+                       ;;
+               --reference=*)
+                       reference="$1"
+                       shift
                        ;;
                --)
                        shift
@@ -204,7 +208,7 @@ cmd_add()
                git config submodule."$path".url "$url"
        else
 
-               module_clone "$path" "$realrepo" || exit
+               module_clone "$path" "$realrepo" "$reference" || exit
                (
                        unset GIT_DIR
                        cd "$path" &&
@@ -257,7 +261,7 @@ cmd_init()
        do
                case "$1" in
                -q|--quiet)
-                       quiet=1
+                       GIT_QUIET=1
                        ;;
                --)
                        shift
@@ -295,10 +299,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
@@ -317,11 +321,11 @@ cmd_update()
                case "$1" in
                -q|--quiet)
                        shift
-                       quiet=1
+                       GIT_QUIET=1
                        ;;
                -i|--init)
+                       init=1
                        shift
-                       cmd_init "$@" || return
                        ;;
                -N|--no-fetch)
                        shift
@@ -329,7 +333,16 @@ cmd_update()
                        ;;
                -r|--rebase)
                        shift
-                       rebase=true
+                       update="rebase"
+                       ;;
+               --reference)
+                       case "$2" in '') usage ;; esac
+                       reference="--reference=$2"
+                       shift 2
+                       ;;
+               --reference=*)
+                       reference="$1"
+                       shift
                        ;;
                --)
                        shift
@@ -344,12 +357,17 @@ cmd_update()
                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)
-               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
@@ -362,7 +380,7 @@ cmd_update()
 
                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" &&
@@ -370,9 +388,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 +408,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'"
@@ -618,7 +638,7 @@ cmd_status()
        do
                case "$1" in
                -q|--quiet)
-                       quiet=1
+                       GIT_QUIET=1
                        ;;
                --cached)
                        cached=1
@@ -672,7 +692,7 @@ cmd_sync()
        do
                case "$1" in
                -q|--quiet)
-                       quiet=1
+                       GIT_QUIET=1
                        shift
                        ;;
                --)
@@ -727,7 +747,7 @@ do
                command=$1
                ;;
        -q|--quiet)
-               quiet=1
+               GIT_QUIET=1
                ;;
        -b|--branch)
                case "$2" in