From 7924ab559000c784f5ff927e8bcbb9853b1498ba Mon Sep 17 00:00:00 2001 From: Imran M Yousuf Date: Sun, 6 Jan 2008 22:20:32 +0600 Subject: [PATCH] - Added the recursively command propagation to the git submodule script --- git-submodule | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 6 deletions(-) diff --git a/git-submodule b/git-submodule index b91d626..eb04f02 100755 --- a/git-submodule +++ b/git-submodule @@ -1,10 +1,11 @@ #!/bin/sh # # git-submodules.sh: add, init, update or list git submodules +# or recurse any git command over the submodules recursively. # # Copyright (c) 2007 Lars Hjemli -USAGE='[--quiet] [--cached] [add [-b branch]|status|init|update] [--] [...]' +USAGE='[[--quiet] [--cached] [add [-b branch]|status|init|update] [--] [...]|[recurse [-v] command arguments ...]]' . git-sh-setup require_work_tree @@ -251,6 +252,78 @@ modules_list() done } +3 Simply checks whether the submodule is initialized +# or not. If not initialized it does so. +initializeSubModule() { + if [ ! -d "$1"/.git ]; then + if [ $recurse_verbose -eq 1 ]; then + echo Initializing and updating "$1" + fi + git-submodule init "$1"; git-submodule update "$1" + fi +} + +# This actually traverses the module; checks +# whether the module is initialized or not. +# if not initialized, then done so and then the +# intended command is evaluated. Then it +# recursively goes into it modules. +traverseModule() { + current_dir=`pwd` + dir_path="$current_dir:$dir_path" + initializeSubModule "$1" + cd "$1" + if [ $recurse_verbose -eq 1 ]; then + echo Working in mod $1 @ `pwd` with $2 + fi + eval "$2" + if [ -f .gitmodules ]; then + for mod_path in `grep "path =" .gitmodules | awk '{print $3}'`; do + traverseModule "$mod_path" "$2" + done + fi + old_dir=$(echo $dir_path | cut -d':' -f1-1) + length_old_dir=`expr "$old_dir" : '.*'` + cd $old_dir + index=$(echo "$length_old_dir+2" | bc) + dir_path=`echo $dir_path $index | awk '{print substr($1, $2)}'` +} + +# Propagates or recurses over all the submodules at any +# depth with any git command, e.g. git-clone, git-status, +# git-commit etc., with the arguments supplied exactly as +# it would have been supplied to the command otherwise. +# This actually starts the recursive propagation +propagate() { + project_home=`pwd` + echo Project Home: $project_home + if [ -d $project_home/.git/ ]; then + git_command=$1 + shift + command_arguments="" + for arg in "$@"; do + if [ `expr index "$arg" ' '` -gt 0 ]; then + arg="\"$arg\"" + fi + command_arguments="$command_arguments $arg" + done + if [ $recurse_verbose -eq 1 ]; then + echo GIT Command git-$git_command with arguments\($#\) "$command_arguments" + fi + main_command="git-$git_command $command_arguments" + eval $main_command + if [ -f .gitmodules ]; then + for mod_path in `grep "path =" .gitmodules | awk '{print $3}'`; do + traverseModule $mod_path "$main_command" + done + fi + else + echo $project_home not a git repo thus exiting + exit + fi +} + +recurse_verbose=0 while test $# != 0 do case "$1" in @@ -286,6 +359,17 @@ do -*) usage ;; + recurse) + recurse=1 + case "$2" in + -v) + recurse_verbose=1 + shift + ;; + esac + shift + break + ;; *) break ;; @@ -303,17 +387,20 @@ case "$add,$branch" in ;; esac -case "$add,$init,$update,$status,$cached" in -1,,,,) +case "$add,$init,$update,$recurse,$status,$cached" in +1,,,,,) module_add "$@" ;; -,1,,,) +,1,,,,) modules_init "$@" ;; -,,1,,) +,,1,,,) modules_update "$@" ;; -,,,*,*) +,,,1,,) + propagate "$@" + ;; +,,,,*,*) modules_list "$@" ;; *) -- 2.11.4.GIT