]> asedeno.scripts.mit.edu Git - git.git/blobdiff - git-submodule.sh
Merge branch 'maint'
[git.git] / git-submodule.sh
index c2ce2fbe8afa924f7f34970a3fb07363abe07452..2a3a197d1057dcc73570a9946d5e5d8d9bbcc959 100755 (executable)
@@ -6,7 +6,7 @@
 
 USAGE="[--quiet] [--cached] \
 [add <repo> [-b branch] <path>]|[status|init|update [-i|--init]|summary [-n|--summary-limit <n>] [<commit>]] \
-[--] [<path>...]"
+[--] [<path>...]|[foreach <command>]"
 OPTIONS_SPEC=
 . git-sh-setup
 require_work_tree
@@ -53,6 +53,15 @@ resolve_relative_url ()
        echo "$remoteurl/$url"
 }
 
+#
+# Get submodule info for registered submodules
+# $@ = path to limit submodule list
+#
+module_list()
+{
+       git ls-files --stage -- "$@" | grep '^160000 '
+}
+
 #
 # Map submodule path to submodule name
 #
@@ -172,6 +181,16 @@ cmd_add()
                else
                        die "'$path' already exists and is not a valid git repo"
                fi
+
+               case "$repo" in
+               ./*|../*)
+                       url=$(resolve_relative_url "$repo") || exit
+                   ;;
+               *)
+                       url="$repo"
+                       ;;
+               esac
+               git config submodule."$path".url "$url"
        else
 
                module_clone "$path" "$realrepo" || exit
@@ -188,6 +207,26 @@ cmd_add()
        die "Failed to register submodule '$path'"
 }
 
+#
+# Execute an arbitrary command sequence in each checked out
+# submodule
+#
+# $@ = command to execute
+#
+cmd_foreach()
+{
+       module_list |
+       while read mode sha1 stage path
+       do
+               if test -e "$path"/.git
+               then
+                       say "Entering '$path'"
+                       (cd "$path" && eval "$@") ||
+                       die "Stopping at '$path'; script returned non-zero status."
+               fi
+       done
+}
+
 #
 # Register submodules in .git/config
 #
@@ -216,7 +255,7 @@ cmd_init()
                shift
        done
 
-       git ls-files --stage -- "$@" | grep '^160000 ' |
+       module_list "$@" |
        while read mode sha1 stage path
        do
                # Skip already registered paths
@@ -254,6 +293,7 @@ cmd_update()
        do
                case "$1" in
                -q|--quiet)
+                       shift
                        quiet=1
                        ;;
                -i|--init)
@@ -271,10 +311,9 @@ cmd_update()
                        break
                        ;;
                esac
-               shift
        done
 
-       git ls-files --stage -- "$@" | grep '^160000 ' |
+       module_list "$@" |
        while read mode sha1 stage path
        do
                name=$(module_name "$path") || exit
@@ -539,7 +578,7 @@ cmd_status()
                shift
        done
 
-       git ls-files --stage -- "$@" | grep '^160000 ' |
+       module_list "$@" |
        while read mode sha1 stage path
        do
                name=$(module_name "$path") || exit
@@ -573,7 +612,7 @@ cmd_status()
 while test $# != 0 && test -z "$command"
 do
        case "$1" in
-       add | init | update | status | summary)
+       add | foreach | init | update | status | summary)
                command=$1
                ;;
        -q|--quiet)