From: Imran M Yousuf <imyousuf@xxxxxxxxxxxxxxxxxxxxxx> There is a scenario which has been put forward several times in discussion over the recurse subcommand and it is that commands chould have different arguments for different modules. For example, one module could want to checkout 'master', while another might want to checkout 'work'. The [-a|--customized-argument] argument provides platform just for that. Consider the following command and its followup for further info: git submodule recurse -a checkout Submodule b is not initialized and skipped git submodule recurse a checkout Please provide an argument: master Press y to provide another arg... git checkout master Already on branch "master" Submodule d is not initialized and skipped git submodule recurse . checkout Please provide an argument: master Press y to provide another arg... git checkout master Already on branch "master" This command would also come in handy for diffs and other commands. Signed-off-by: Imran M Yousuf <imyousuf@xxxxxxxxxxxxxxxxxxxxxx> --- git-submodule.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 49 insertions(+), 4 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 8161d51..314652d 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -12,7 +12,7 @@ LONG_USAGE="$0 add [-q|--quiet] [-b|--branch branch] <repository> [<path>] $0 [status] [-q|--quiet] [-c|--cached] [--] [<path>...] $0 init|update [-q|--quiet] [--] [<path>...] $0 summary [--cached] [-n|--summary-limit <n>] [<commit>] -$0 recurse [-q|--quiet] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-b|--breadth-first] <git command> [<args> ...]" +$0 recurse [-q|--quiet] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-b|--breadth-first] [-a|--customized-argument] <git command> [<args> ...]" OPTIONS_SPEC= . git-sh-setup require_work_tree @@ -25,6 +25,8 @@ depth=0 current_depth=0 depth_first=1 on_error= +use_custom_args= +custom_args= # # print stuff on stdout unless -q was specified @@ -585,6 +587,40 @@ cmd_status() done } +# Take arguments from user to pass as custom arguments and execute the command +exec_with_custom_args() +{ + input= + arg_index=0 + eval_str="set " + while test $# -gt 0 + do + arg_index=$(($arg_index + 1)) + var='$'"$arg_index" + input="$1" + eval_str="$eval_str $var \"$input\"" + shift + done + while : + do + arg_index=$(($arg_index + 1)) + printf "Please provide an argument: " + read input + var='$'"$arg_index" + eval_str="$eval_str $var \"$input\"" + printf "Press y to provide another arg... " + read keypress + if test "$keypress" != "y" && + test "$keypress" != "Y" + then + break + fi + done + eval $eval_str + say "$*" + "$@" +} + # Check whether the submodule is initialized or not initialize_sub_module() { @@ -637,10 +673,16 @@ traverse_module() # If depth-first is specified in that case submodules are # are traversed before executing the command on this submodule test -n "$depth_first" && traverse_submodules "$@" - # pwd is mentioned in order to enable the ser to distinguish - # between same name modules, e.g. a/lib and b/lib. say "git submodule recurse $submod_path $*" - git "$@" + if test -n "$use_custom_args" + then + # Execute the commands after taking the arguments + # Please note that one input is for one argument + # only. + exec_with_custom_args git "$@" + else + git "$@" + fi # if exit on error is specifed than script will exit if any # command fails. As there is no transaction there will be # no rollback either @@ -689,6 +731,9 @@ cmd_recurse() { -e|--exit-after-error) on_error=1 ;; + -a|--customized-argument) + use_custom_args=1 + ;; -*) usage ;; -- 1.5.4.2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html