{"thread":{"id":"12532","subject":"[PATCH] - Added command synopsis in code and edited them in manual","startedAt":"2008-03-06T07:33:33Z","lastAt":"2008-03-06T10:42:36Z","messageCount":8,"participants":["imyousuf@gmail.com","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"71203","messageId":"1204788817-22720-1-git-send-email-imyousuf@gmail.com","threadId":"12532","inReplyTo":null,"subject":"[PATCH] - Added command synopsis in code and edited them in manual","fromName":"","fromEmail":"imyousuf@gmail.com","sentAt":"2008-03-06T07:33:33Z","receivedAt":"2008-03-06T07:33:33Z","isPatch":true,"sender":{"key":"imyousuf@gmail.com","avatar":"https://gravatar.com/avatar/fda3c870262849d03c7b9c4d288842e128d6d80769fa7bc2d22731b7597928be?d=mp&s=160"},"body":"From: Imran M Yousuf <imyousuf@smartitengineering.com>\n\nAdded the command synopsis so that they are available for\nany future command additions.\n\nQuiet can also be specified using -q and it was missing in\nthe usage in the code and man page.\n\nIn the init/update command synopsis either of them is required\ncommand as is add in its synopsis, so removed the square brackets\naround them from the documentation\n\nSigned-off-by: Imran M Yousuf <imyousuf@smartitengineering.com>\n---\n Documentation/git-submodule.txt |    6 +++---\n git-submodule.sh                |    6 +++++-\n 2 files changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex e818e6e..595918e 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -9,9 +9,9 @@ git-submodule - Initialize, update or inspect submodules\n SYNOPSIS\n --------\n [verse]\n-'git-submodule' [--quiet] add [-b branch] [--] <repository> [<path>]\n-'git-submodule' [--quiet] status [--cached] [--] [<path>...]\n-'git-submodule' [--quiet] [init|update] [--] [<path>...]\n+'git-submodule' [-q|--quiet] add [-b branch] [--] <repository> [<path>]\n+'git-submodule' [-q|--quiet] [status] [--cached] [--] [<path>...]\n+'git-submodule' [-q|--quiet] init|update [--] [<path>...]\n \n \n COMMANDS\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 67d3224..257be4c 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -4,7 +4,11 @@\n #\n # Copyright (c) 2007 Lars Hjemli\n \n-USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'\n+# Synopsis of this commands are as follows\n+# git-submodule [-q|--quiet] add [-b|--branch branch] <repository> [<path>]\n+# git-submodule [-q|--quiet] [status] [-c|--cached] [--] [<path>...]\n+# git-submodule [-q|--quiet] init|update [--] [<path>...]\n+USAGE='[-q|--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'\n OPTIONS_SPEC=\n . git-sh-setup\n require_work_tree\n-- \n1.5.4.2\n\n"},{"id":"71204","messageId":"1204788817-22720-2-git-send-email-imyousuf@gmail.com","threadId":"12532","inReplyTo":"1204788817-22720-1-git-send-email-imyousuf@gmail.com","subject":"[PATCH] - Added 'recurse' subcommand to git submodule","fromName":"","fromEmail":"imyousuf@gmail.com","sentAt":"2008-03-06T07:33:34Z","receivedAt":"2008-03-06T07:33:34Z","isPatch":true,"sender":{"key":"imyousuf@gmail.com","avatar":"https://gravatar.com/avatar/fda3c870262849d03c7b9c4d288842e128d6d80769fa7bc2d22731b7597928be?d=mp&s=160"},"body":"From: Imran M Yousuf <imyousuf@smartitengineering.com>\n\nThe purpose of the recurse command in the git submodule is to recurse\na command in its submodule. For example if one wants to do a diff on its\nproject with submodules at once, one can simply do\n\tgit-submodule recurse diff HEAD\nand would see the diff for all the modules it contains.\n\nThe recurse commands behavior can be customized with several arguments\nthat it accepts. The synopsis for the recurse command is:\n\n\tgit-submodule [-q|--quiet] recurse [-i|--initialize]\n\t[-e|--exit-after-error] [-d|--depth <recursion depth>]\n\t[-df|--depth-first] [-ca|--customized-argument] [-p|--pre-command]\n\t<command> [<arguments> ...]\n\nWhen traversing modules, a module could be uninitialized that is git\nsubmodule init and update has not been called for it; if [-i|--initialize]\noption is specified, it will initialize any module that is not initialized;\nelse if the module is not initialized it will simply skip it.\n\nThere are commands that can fail for a certain submodule but succeed for\nothers; if one wants to stop execution once the top level module's execution\nfails, one can specify [-e|--exit-after-error]. It will ensure that once\nexecution of git <command> fails in the top level module it will not recurse\ninto its submodules.\n\nIf the project has submodule hierarchy upto n depth and we want to restrict\nrecursion to (n-p) depth; we can use the [-d|--depth <recursion depth>] option.\nValue has to be greater than 0 and command will at least recurse into the first\ndepth. If depth is specified to p than all depths <= p will be recursed over.\n\nWhile discussion on the recurse command one thing which was put forward\nin several occassions is that there might be scenario where a command should be\nexecuted over the child module before the parent module. For such scenario\n[-df|--depth-first] option can be used; one use case in particualar presented\nas an example is git commit; where almost everybody mentioned that they prefer\nto commit the child module before the parent and -df will enable just that.\nE.g. p -> a, b, c, e; a ->d is a module structure. If the following command is\nused,\n\tgit submodule recurse -df commit -a\nit will execute git commit -a in the following sequence - d, a, b, c, e, p.\n\nSigned-off-by: Imran M Yousuf <imyousuf@smartitengineering.com>\n---\n git-submodule.sh |  162 +++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 160 insertions(+), 2 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 257be4c..ee3c928 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -8,7 +8,8 @@\n # git-submodule [-q|--quiet] add [-b|--branch branch] <repository> [<path>]\n # git-submodule [-q|--quiet] [status] [-c|--cached] [--] [<path>...]\n # git-submodule [-q|--quiet] init|update [--] [<path>...]\n-USAGE='[-q|--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'\n+# git-submodule [-q|--quiet] recurse [-i|--initialize] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-df|--depth-first] <command> [<arguments> ...]\n+USAGE='[-q|--quiet] [[[add [-b|--branch branch] <repo>]|[[[status [-c|--cached]]|init|update] [--]]]  [<path>...]]|[recurse [-i|--initialize] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-df|--depth-first] <command> [<arguments> ...]]'\n OPTIONS_SPEC=\n . git-sh-setup\n require_work_tree\n@@ -17,6 +18,11 @@ command=\n branch=\n quiet=\n cached=\n+depth=0\n+current_depth=0\n+auto_initialize=\n+depth_first=\n+on_error=\n \n #\n # print stuff on stdout unless -q was specified\n@@ -386,6 +392,157 @@ cmd_status()\n \tdone\n }\n \n+# Initializes the submodule if already not initialized\n+# and auto initialize is enabled\n+initialize_sub_module()\n+{\n+\tif test ! -d \"$1\"/.git &&\n+\t   test -n \"$auto_initialize\"\n+\tthen\n+\t\tsay \"Initializing and updating $1\"\n+\t\tgit-submodule init \"$1\" &&\n+\t\tgit-submodule update \"$1\" &&\n+\t\treturn 0\n+\t# Returns true if module is already initialized\n+\telif test -d \"$1\"/.git\n+\tthen\n+\t\treturn 0\n+\tfi\n+\tsay \"Module $1 is not initialized and skipped\"\n+\treturn 1\n+}\n+\n+# This module simply checks whether the depth is traverseable\n+# in terms of depth and if so then it sequentially traverses\n+# its submodules\n+traverse_submodules()\n+{\n+\t# If current depth is the range specified than it will continue\n+\t# else return with success\n+\tif test \"$depth\" -gt 0 &&\n+\t\ttest \"$current_depth\" -ge \"$depth\"\n+\tthen\n+\t\treturn 0;\n+\tfi\n+\t# If submodules exists than it will traverse over them\n+\tif test -f .gitmodules\n+\tthen\n+\t\t# Incrementing the depth for the next level of submodules\n+\t\tcurrent_depth=$(($current_depth + 1))\n+                for mod_path in `sed -n -e 's/path = //p' .gitmodules`; do\n+                        traverse_module \"$mod_path\" \"$@\"\n+                done\n+\t\t# Decremented the depth to bring it back to the depth of\n+\t\t# the current module\n+\t\tcurrent_depth=$(($current_depth - 1))\n+\tfi\n+}\n+\n+# This actually traverses a module; checks\n+# whether the module is initialized or not.\n+# if not initialized, then tries to do so \n+# based on the user preference and then the\n+# intended command is evaluated in the \n+# traversal manner requested - breadth first \n+# or depth first. Then it# recursively goes \n+# into it modules.\n+traverse_module()\n+{\n+\t# Will work in the module if and only if the module is initialized\n+\tinitialize_sub_module \"$1\" &&\n+\t(\n+\t\tsubmod_path=\"$1\"\n+\t\tshift\n+\t\tcd \"$submod_path\"\n+\t\t# If depth-first is specified in that case submodules are\n+\t\t# are traversed before executing the command on this module\n+\t\ttest -n \"$depth_first\" && traverse_submodules \"$@\"\n+\t\t# pwd is mentioned in order to enable the ser to distinguish\n+\t\t# between same name modules, e.g. a/lib and b/lib.\n+\t\tsay \"Working in mod $submod_path\" @ `pwd` \"with $@ ($#)\"\n+\t\tcmd_status=\n+\t\tgit \"$@\" || cmd_status=1\n+\t\t# if exit on error is specifed than script will exit if any\n+\t\t# command fails. As there is no transaction there will be\n+\t\t# no rollback either\n+\t\t# TODO - If possible facilitate transaction\n+\t\tif  test -n \"$cmd_status\" && test -n \"$on_error\"\n+\t\tthen\n+\t\t\tdie \"git $@ failed in module $submod_path @ $(pwd)\"\n+\t\tfi\n+\t\t# If depth-first is not specified in that case submodules are\n+\t\t# are traversed after executing the command on this module\n+\t\ttest -z \"$depth_first\" && traverse_submodules \"$@\"\n+\t)\n+}\n+\n+# Propagates or recurses over all the submodules at any\n+# depth with any git command, e.g. git-clone, git-status,\n+# git-commit etc., with the arguments supplied exactly as\n+# it would have been supplied to the command otherwise.\n+# This actually starts the recursive propagation\n+cmd_recurse() {\n+\twhile :\n+\tdo\n+\t\tcase \"$1\" in\n+\t\t-q|--quiet)\n+                \tquiet=1\n+                \t;;\n+\t\t-d|--depth)\n+\t\t\tshift\n+\t\t\tif test -z \"$1\"\n+\t\t\tthen\n+\t\t\t\techo \"No <recursion depth> specified\"\n+\t\t\t\tusage\n+\t\t\t# Arithmatic operation will give an error if depth is not number\n+\t\t\t# thus chose to check intergerness with regular expression\n+\t\t\telif test \"$(expr $1 : '[1-9][0-9]*')\" -eq \"$(expr $1 : '.*')\"\n+\t\t\tthen\n+\t\t\t\tdepth=\"$1\"\n+\t\t\telse\n+\t\t\t\techo \"<recursion depth> not an integer\"\n+\t\t\t\tusage\n+\t\t\tfi\n+\t\t\t;;\n+\t\t-df|--depth-first)\n+\t\t\tdepth_first=1\n+\t\t\t;;\n+\t\t-e|--exit-after-error)\n+\t\t\ton_error=1\n+\t\t\t;;\n+\t\t-i|--initialize)\n+\t\t\tauto_initialize=1\n+\t\t\t;;\n+\t\t-p|--pre-command)\n+\t\t\tpre_cmd=1\n+\t\t\t;;\n+\t\t-ca|--customized-argument)\n+\t\t\tuse_custom_args=1\n+\t\t\t;;\n+\t\t-*)\n+\t\t\tusage\n+\t\t\t;;\n+\t\t*)\n+\t\t\tbreak\n+\t\t\t;;\n+\t\tesac\n+\t\tshift\n+\tdone\n+\ttest \"$#\" -le 0 && die \"No git command specified\"\n+\tproject_home=\"$(pwd)\"\n+\tif test \"$depth\" -gt 0\n+\tthen\n+\t\tsay Command will recurse upto \"$depth\" depth\n+\tfi\n+\tif test -d \"$project_home\"/.git/\n+\tthen\n+\t\tsay \"Command to recurse: git $@\"\n+\t\ttraverse_module . \"$@\"\n+\telse\n+\t\tdie \"$project_home not a git repo thus exiting\"\n+\tfi\n+}\n+\n # This loop parses the command line arguments to find the\n # subcommand name to dispatch.  Parsing of the subcommand specific\n # options are primarily done by the subcommand implementations.\n@@ -395,7 +552,7 @@ cmd_status()\n while test $# != 0 && test -z \"$command\"\n do\n \tcase \"$1\" in\n-\tadd | init | update | status)\n+\tadd | init | update | status | recurse)\n \t\tcommand=$1\n \t\t;;\n \t-q|--quiet)\n@@ -441,3 +598,4 @@ then\n fi\n \n \"cmd_$command\" \"$@\"\n+\n-- \n1.5.4.2\n\n"},{"id":"71205","messageId":"1204788817-22720-3-git-send-email-imyousuf@gmail.com","threadId":"12532","inReplyTo":"1204788817-22720-2-git-send-email-imyousuf@gmail.com","subject":"[PATCH] - Added pre command and custom argument support to git submodule recurse command","fromName":"","fromEmail":"imyousuf@gmail.com","sentAt":"2008-03-06T07:33:35Z","receivedAt":"2008-03-06T07:33:35Z","isPatch":true,"sender":{"key":"imyousuf@gmail.com","avatar":"https://gravatar.com/avatar/fda3c870262849d03c7b9c4d288842e128d6d80769fa7bc2d22731b7597928be?d=mp&s=160"},"body":"From: Imran M Yousuf <imyousuf@smartitengineering.com>\n\nThere is one scenario that has been put forward several times in\ndiscussion over the recurse command - it is that commands can have\ndifferent arguments for different modules. For example for the same example\nmentioned above, one wants to check a_1 for submdoule a, while it wants to\ncheckout d_2 for d. It can be achieved by using [-ca|--customized-argument].\nThis results the script to prompt for user input, which will be passed as\nargument to the command for that module.\n\tgit submodule recurse -ca checkout\n\tWorking in mod a .......\n\tPlease provide arguments for this module: a_1\n\tWorking in mod d .......\n\tPlease provide arguments for this module: a_1\n\nIt is usually helpful that when typing a command, being able to see some options\ncome in handy. For example if I can see the available branches before checking\nout a branch that would be useful, IOW, if one could git branch before git\ncheckout; it is now possible using the [-p|--pre-command] option. Using this\ncommand you can actually execute other git commands before specifying the\narguments to the original command. E.g. if the above command is changed to,\n\tgit submodule recurse -ca -p checkout\nit will prompt the user for the pre command until one is satisfied and later\nthe user can actually use them in the argument.\n\nAs these two options get along well together it made sense to me\nto group them together.\n\nSigned-off-by: Imran M Yousuf <imyousuf@smartitengineering.com>\n---\n git-submodule.sh |   33 +++++++++++++++++++++++++++++----\n 1 files changed, 29 insertions(+), 4 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex ee3c928..05fd1d2 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -8,8 +8,8 @@\n # git-submodule [-q|--quiet] add [-b|--branch branch] <repository> [<path>]\n # git-submodule [-q|--quiet] [status] [-c|--cached] [--] [<path>...]\n # git-submodule [-q|--quiet] init|update [--] [<path>...]\n-# git-submodule [-q|--quiet] recurse [-i|--initialize] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-df|--depth-first] <command> [<arguments> ...]\n-USAGE='[-q|--quiet] [[[add [-b|--branch branch] <repo>]|[[[status [-c|--cached]]|init|update] [--]]]  [<path>...]]|[recurse [-i|--initialize] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-df|--depth-first] <command> [<arguments> ...]]'\n+# git-submodule [-q|--quiet] recurse [-i|--initialize] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-df|--depth-first] [-ca|--customized-argument] [-p|--pre-command] <command> [<arguments> ...]\n+USAGE='[-q|--quiet] [[[add [-b|--branch branch] <repo>]|[[[status [-c|--cached]]|init|update] [--]]]  [<path>...]]|[recurse [-i|--initialize] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-df|--depth-first] [-ca|--customized-argument] [-p|--pre-command] <command> [<arguments> ...]]'\n OPTIONS_SPEC=\n . git-sh-setup\n require_work_tree\n@@ -392,6 +392,30 @@ cmd_status()\n \tdone\n }\n \n+do_pre_command()\n+{\n+\tsay \"Starting pre-comamnd execution!\"\n+\twhile :\n+\tdo\n+\t\t(\n+\t\t\tread -p \"Please provide a git command: \" pre_command\n+\t\t\ttest -z \"$pre_command\" || git \"$pre_command\"\n+\t\t)\n+\t\tread -p \"Press y to continue with another git command... \" keypress\n+\t\tif test \"$keypress\" != \"y\" &&\n+\t\t\ttest \"$keypress\" != \"Y\"\n+\t\tthen\n+\t\t\tbreak\n+\t\tfi\n+\tdone\n+}\n+\n+# Take arguments from user to pass as custom arguments\n+get_custom_args()\n+{\n+\tread -p \"Please provide arguments for this module: \" custom_args\n+}\n+\n # Initializes the submodule if already not initialized\n # and auto initialize is enabled\n initialize_sub_module()\n@@ -460,8 +484,10 @@ traverse_module()\n \t\t# pwd is mentioned in order to enable the ser to distinguish\n \t\t# between same name modules, e.g. a/lib and b/lib.\n \t\tsay \"Working in mod $submod_path\" @ `pwd` \"with $@ ($#)\"\n+\t\ttest -n \"$pre_cmd\" && do_pre_command\n+\t\ttest -n \"$use_custom_args\" && get_custom_args\n \t\tcmd_status=\n-\t\tgit \"$@\" || cmd_status=1\n+\t\tgit \"$@\" \"$custom_args\" || cmd_status=1\n \t\t# if exit on error is specifed than script will exit if any\n \t\t# command fails. As there is no transaction there will be\n \t\t# no rollback either\n@@ -598,4 +624,3 @@ then\n fi\n \n \"cmd_$command\" \"$@\"\n"},{"id":"71206","messageId":"1204788817-22720-4-git-send-email-imyousuf@gmail.com","threadId":"12532","inReplyTo":"1204788817-22720-3-git-send-email-imyousuf@gmail.com","subject":"[PATCH] - Added pre command and custom argument support to git submodule recurse command","fromName":"","fromEmail":"imyousuf@gmail.com","sentAt":"2008-03-06T07:33:36Z","receivedAt":"2008-03-06T07:33:36Z","isPatch":true,"sender":{"key":"imyousuf@gmail.com","avatar":"https://gravatar.com/avatar/fda3c870262849d03c7b9c4d288842e128d6d80769fa7bc2d22731b7597928be?d=mp&s=160"},"body":"A noteworthy change is that modules_list() is now known as\ncmd_status().  There is no \"submodule list\" command.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * We could probably do something like this.  This first part is\n   about making the command dispatcher maintainable.\n\n   Note that I haven't seriously tested this series.  This and\n   the next one are primarily to illustrate what I think the fix\n   you are trying should look like.\n\n git-submodule.sh |   20 ++++++++++----------\n 1 files changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex ad9fe62..3c104e3 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -86,9 +86,9 @@ module_name()\n #\n # Clone a submodule\n #\n-# Prior to calling, modules_update checks that a possibly existing\n+# Prior to calling, cmd_update checks that a possibly existing\n # path is not a git repository.\n-# Likewise, module_add checks that path does not exist at all,\n+# Likewise, cmd_add checks that path does not exist at all,\n # since it is the location of a new submodule.\n #\n module_clone()\n@@ -121,7 +121,7 @@ module_clone()\n #\n # optional branch is stored in global branch variable\n #\n-module_add()\n+cmd_add()\n {\n        repo=$1\n        path=$2\n@@ -174,7 +174,7 @@ module_add()\n #\n # $@ = requested paths (default to all)\n #\n-modules_init()\n+cmd_init()\n {\n        git ls-files --stage -- \"$@\" | grep -e '^160000 ' |\n        while read mode sha1 stage path\n@@ -207,7 +207,7 @@ modules_init()\n #\n # $@ = requested paths (default to all)\n #\n-modules_update()\n+cmd_update()\n {\n        git ls-files --stage -- \"$@\" | grep -e '^160000 ' |\n        while read mode sha1 stage path\n@@ -266,7 +266,7 @@ set_name_rev () {\n #\n # $@ = requested paths (default to all)\n #\n-modules_list()\n+cmd_status()\n {\n        git ls-files --stage -- \"$@\" | grep -e '^160000 ' |\n        while read mode sha1 stage path\n@@ -347,16 +347,16 @@ esac\n\n case \"$add,$init,$update,$status,$cached\" in\n 1,,,,)\n-       module_add \"$@\"\n+       cmd_add \"$@\"\n        ;;\n ,1,,,)\n-       modules_init \"$@\"\n+       cmd_init \"$@\"\n        ;;\n ,,1,,)\n-       modules_update \"$@\"\n+       cmd_update \"$@\"\n        ;;\n ,,,*,*)\n-       modules_list \"$@\"\n+       cmd_status \"$@\"\n        ;;\n *)\n        usage\n--\n1.5.3.7\n"},{"id":"71207","messageId":"1204788817-22720-5-git-send-email-imyousuf@gmail.com","threadId":"12532","inReplyTo":"1204788817-22720-4-git-send-email-imyousuf@gmail.com","subject":"[PATCH] - Added pre command and custom argument support to git submodule recurse command","fromName":"","fromEmail":"imyousuf@gmail.com","sentAt":"2008-03-06T07:33:37Z","receivedAt":"2008-03-06T07:33:37Z","isPatch":true,"sender":{"key":"imyousuf@gmail.com","avatar":"https://gravatar.com/avatar/fda3c870262849d03c7b9c4d288842e128d6d80769fa7bc2d22731b7597928be?d=mp&s=160"},"body":"    $ git submodule add init update\n\nwhich is meant to add a submodule called 'init' at path 'update'\nwas misinterpreted as a request to invoke more than one mutually\nincompatible subcommands and incorrectly rejected.\n\nThis patch fixes the issue by stopping the subcommand parsing at\nthe first subcommand word, to allow the sample command line\nabove to work as expected.\n\nIt also introduces the usual -- option disambiguator, so that a\nsubmodule at path '-foo' can be updated with\n\n    $ git submodule update -- -foo\n\nwithout triggering an \"unrecognized option -foo\" error.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * And this is the second part to fix the real issue.\n\n git-submodule.sh |  157 ++++++++++++++++++++++++++++++++++++++++--------------\n 1 files changed, 116 insertions(+), 41 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 3c104e3..a6aaf40 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -9,11 +9,8 @@ OPTIONS_SPEC=\n . git-sh-setup\n require_work_tree\n\n-add=\n+command=\n branch=\n-init=\n-update=\n-status=\n quiet=\n cached=\n\n@@ -123,6 +120,32 @@ module_clone()\n #\n cmd_add()\n {\n+       # parse $args after \"submodule ... add\".\n+       while test $# -ne 0\n+       do\n+               case \"$1\" in\n+               -b | --branch)\n+                       case \"$2\" in '') usage ;; esac\n+                       branch=$2\n+                       shift\n+                       ;;\n+               -q|--quiet)\n+                       quiet=1\n+                       ;;\n+               --)\n+                       shift\n+                       break\n+                       ;;\n+               -*)\n+                       usage\n+                       ;;\n+               *)\n+                       break\n+                       ;;\n+               esac\n+               shift\n+       done\n+\n        repo=$1\n        path=$2\n\n@@ -176,6 +199,27 @@ cmd_add()\n #\n cmd_init()\n {\n+       # parse $args after \"submodule ... init\".\n+       while test $# -ne 0\n+       do\n+               case \"$1\" in\n+               -q|--quiet)\n+                       quiet=1\n+                       ;;\n+               --)\n+                       shift\n+                       break\n+                       ;;\n+               -*)\n+                       usage\n+                       ;;\n+               *)\n+                       break\n+                       ;;\n+               esac\n+               shift\n+       done\n+\n        git ls-files --stage -- \"$@\" | grep -e '^160000 ' |\n        while read mode sha1 stage path\n        do\n@@ -209,6 +253,27 @@ cmd_init()\n #\n cmd_update()\n {\n+       # parse $args after \"submodule ... update\".\n+       while test $# -ne 0\n+       do\n+               case \"$1\" in\n+               -q|--quiet)\n+                       quiet=1\n+                       ;;\n+               --)\n+                       shift\n+                       break\n+                       ;;\n+               -*)\n+                       usage\n+                       ;;\n+               *)\n+                       break\n+                       ;;\n+               esac\n+               shift\n+       done\n+\n        git ls-files --stage -- \"$@\" | grep -e '^160000 ' |\n        while read mode sha1 stage path\n        do\n@@ -268,6 +333,30 @@ set_name_rev () {\n #\n cmd_status()\n {\n+       # parse $args after \"submodule ... status\".\n+       while test $# -ne 0\n+       do\n+               case \"$1\" in\n+               -q|--quiet)\n+                       quiet=1\n+                       ;;\n+               --cached)\n+                       cached=1\n+                       ;;\n+               --)\n+                       shift\n+                       break\n+                       ;;\n+               -*)\n+                       usage\n+                       ;;\n+               *)\n+                       break\n+                       ;;\n+               esac\n+               shift\n+       done\n+\n        git ls-files --stage -- \"$@\" | grep -e '^160000 ' |\n        while read mode sha1 stage path\n        do\n@@ -293,20 +382,17 @@ cmd_status()\n        done\n }\n\n-while test $# != 0\n+# This loop parses the command line arguments to find the\n+# subcommand name to dispatch.  Parsing of the subcommand specific\n+# options are primarily done by the subcommand implementations.\n+# Subcommand specific options such as --branch and --cached are\n+# parsed here as well, for backward compatibility.\n+\n+while test $# != 0 && test -z \"$command\"\n do\n        case \"$1\" in\n-       add)\n-               add=1\n-               ;;\n-       init)\n-               init=1\n-               ;;\n-       update)\n-               update=1\n-               ;;\n-       status)\n-               status=1\n+       add | init | update | status)\n+               command=$1\n                ;;\n        -q|--quiet)\n                quiet=1\n@@ -335,30 +421,19 @@ do\n        shift\n done\n\n-case \"$add,$branch\" in\n-1,*)\n-       ;;\n-,)\n-       ;;\n-,*)\n+# No command word defaults to \"status\"\n+test -n \"$command\" || command=status\n+\n+# \"-b branch\" is accepted only by \"add\"\n+if test -n \"$branch\" && test \"$command\" != add\n+then\n        usage\n-       ;;\n-esac\n-\n-case \"$add,$init,$update,$status,$cached\" in\n-1,,,,)\n-       cmd_add \"$@\"\n-       ;;\n-,1,,,)\n-       cmd_init \"$@\"\n-       ;;\n-,,1,,)\n-       cmd_update \"$@\"\n-       ;;\n-,,,*,*)\n-       cmd_status \"$@\"\n-       ;;\n-*)\n+fi\n+\n+# \"--cached\" is accepted only by \"status\"\n+if test -n \"$cached\" && test \"$command\" != status\n+then\n        usage\n-       ;;\n-esac\n+fi\n+\n+\"cmd_$command\" \"$@\"\n--\n1.5.4.rc3.11.g4e67\n"},{"id":"71221","messageId":"7vr6eo9lrt.fsf@gitster.siamese.dyndns.org","threadId":"12532","inReplyTo":"1204788817-22720-2-git-send-email-imyousuf@gmail.com","subject":"Re: [PATCH] - Added 'recurse' subcommand to git submodule","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-06T10:42:14Z","receivedAt":"2008-03-06T10:42:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"imyousuf@gmail.com writes:\n\n> The purpose of the recurse command in the git submodule is to recurse\n\ns/command/sub&/;\n\n> a command in its submodule. For example if one wants to do a diff on its\n> project with submodules at once, one can simply do\n> \tgit-submodule recurse diff HEAD\n> and would see the diff for all the modules it contains.\n\nCan we please have a blank line around the example command line to make it\nvisually stand out more?\n\n> The recurse commands behavior can be customized with several arguments\n> that it accepts. The synopsis for the recurse command is:\n>\n> \tgit-submodule [-q|--quiet] recurse [-i|--initialize]\n> \t[-e|--exit-after-error] [-d|--depth <recursion depth>]\n> \t[-df|--depth-first] [-ca|--customized-argument] [-p|--pre-command]\n> \t<command> [<arguments> ...]\n>\n> When traversing modules, a module could be uninitialized that is git\n> submodule init and update has not been called for it; if [-i|--initialize]\n> option is specified, it will initialize any module that is not initialized;\n> else if the module is not initialized it will simply skip it.\n\nI really do not think the -i option should exist.  \"init\" is a conscious\naction and should not be a side effect of something else.  (Why doesn't\n\"git submodule status -i\" exist? ;-)\n\nI do not mind \"git submodule recurse init\", though.  \"git submodule\nrecurse update\" might also be a natural thing to do.\n\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 257be4c..ee3c928 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -8,7 +8,8 @@\n>  # git-submodule [-q|--quiet] add [-b|--branch branch] <repository> [<path>]\n>  # git-submodule [-q|--quiet] [status] [-c|--cached] [--] [<path>...]\n>  # git-submodule [-q|--quiet] init|update [--] [<path>...]\n> -USAGE='[-q|--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'\n> +# git-submodule [-q|--quiet] recurse [-i|--initialize] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-df|--depth-first] <command> [<arguments> ...]\n> +USAGE='[-q|--quiet] [[[add [-b|--branch branch] <repo>]|[[[status [-c|--cached]]|init|update] [--]]]  [<path>...]]|[recurse [-i|--initialize] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-df|--depth-first] <command> [<arguments> ...]]'\n\nI commented on the overlong USAGE and also not-so-useful comments that\nwould only hurt maintainability in the previous message.  The comment you\nhave above would look reasonably good in LONG_USAGE without leading \"#\",\ndon't you think?\n\n> +# This module simply checks whether the depth is traverseable\n\ns/module/function/; I wouldn't nitpick like this, but in the context of\n\"git-submodule\", saying \"module\" when you do not mean the _module_ you are\nworking on is misleading.\n\n> +# This actually traverses a module; checks\n> +# whether the module is initialized or not.\n> +# if not initialized, then tries to do so \n> +# based on the user preference and then the\n> +# intended command is evaluated in the \n> +# traversal manner requested - breadth first \n> +# or depth first. Then it# recursively goes \n> +# into it modules.\n\nOvernarrow lines are harder to read as well as overlong ones...\n\n> +traverse_module()\n> +{\n> +\t# Will work in the module if and only if the module is initialized\n> +\tinitialize_sub_module \"$1\" &&\n> +\t(\n> +\t\tsubmod_path=\"$1\"\n> +\t\tshift\n> +\t\tcd \"$submod_path\"\n> +\t\t# If depth-first is specified in that case submodules are\n> +\t\t# are traversed before executing the command on this module\n> +\t\ttest -n \"$depth_first\" && traverse_submodules \"$@\"\n> +\t\t# pwd is mentioned in order to enable the ser to distinguish\n> +\t\t# between same name modules, e.g. a/lib and b/lib.\n> +\t\tsay \"Working in mod $submod_path\" @ `pwd` \"with $@ ($#)\"\n\nThis feels more like a debug message than progress report useful for the\nend users.  Perhaps:\n\n\tsay \"git submodule recurse $submod_path $*\"\n\n(which is modeled after how \"diff -r\" repeats itself) would be enough.\n\nBy the way, please make it the habit of using $@ only when you are asking\nfor the magic field splitting with \"$@\"; interpolating all params inside a\nsingle string should be done with \"$*\".  say() happens to take multiple\nparameters, so your code happens to work Ok, but it is error prone; I do\nnot think you deliberately tried to send multiple parameters to the above\n\"say\" by using \"$@\", knowing what this piece of code would do:\n\n\tfrotz () {\n        \techo $#; for i; do echo $i; done\n\t}\n\tset b c d\n        frotz \"a $@ e\"\n\n> +\t\tcmd_status=\n> +\t\tgit \"$@\" || cmd_status=1\n> +\t\t# if exit on error is specifed than script will exit if any\n> +\t\t# command fails. As there is no transaction there will be\n> +\t\t# no rollback either\n> +\t\t# TODO - If possible facilitate transaction\n\nYou can test $? here without $cmd_status.\n\n> +\t\tif  test -n \"$cmd_status\" && test -n \"$on_error\"\n\nExcess SP between \"if test\".\n\n> +\t\tthen\n> +\t\t\tdie \"git $@ failed in module $submod_path @ $(pwd)\"\n\nSame issue with $@ vs $*, and excess $submod_path vs the remainder cruft.\n\nIf the issue you wanted to solve with $(pwd) was that $submod_path is a\nlocal path within the current submodule, a better way to solve it would be\nto pass another \"full path from the top\" around when recursing into a new\nsublevel.\n\n> +# Propagates or recurses over all the submodules at any\n> +# depth with any git command, e.g. git-clone, git-status,\n> +# git-commit etc., with the arguments supplied exactly as\n> +# it would have been supplied to the command otherwise.\n> +# This actually starts the recursive propagation\n> +cmd_recurse() {\n> +\twhile :\n> +\tdo\n> ...\n> +\t\t\telif test \"$(expr $1 : '[1-9][0-9]*')\" -eq \"$(expr $1 : '.*')\"\n\nWhat is this doing?  $1 is underquoted here, by the way.\n\n> +\t\t-df|--depth-first)\n> +\t\t\tdepth_first=1\n> +\t\t\t;;\n\nSingle dash followed by two letters is a somewhat unconventional option\nflag.\n\n> +\t\t-ca|--customized-argument)\n> +\t\t\tuse_custom_args=1\n> +\t\t\t;;\n\nWho uses this and other options?  The series seems to be split\nincorrectly.\n\n> +\tproject_home=\"$(pwd)\"\n> +\tif test \"$depth\" -gt 0\n> +\tthen\n> +\t\tsay Command will recurse upto \"$depth\" depth\n> +\tfi\n> +\tif test -d \"$project_home\"/.git/\n> +\tthen\n> +\t\tsay \"Command to recurse: git $@\"\n> +\t\ttraverse_module . \"$@\"\n\nThese \"say\" are too noisy, compared to other existing uses.  It feels as\nif the command is being run with --debug option.\n\n> @@ -441,3 +598,4 @@ then\n>  fi\n>  \n>  \"cmd_$command\" \"$@\"\n> +\n\nAdds trailing blank line.\n"},{"id":"71224","messageId":"7vlk4w9lri.fsf@gitster.siamese.dyndns.org","threadId":"12532","inReplyTo":"1204788817-22720-3-git-send-email-imyousuf@gmail.com","subject":"Re: [PATCH] - Added pre command and custom argument support to git submodule recurse command","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-06T10:42:25Z","receivedAt":"2008-03-06T10:42:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"imyousuf@gmail.com writes:\n\n> From: Imran M Yousuf <imyousuf@smartitengineering.com>\n>\n> There is one scenario that has been put forward several times in\n> discussion over the recurse command - it is that commands can have\n> different arguments for different modules. For example for the same example\n> mentioned above, one wants to check a_1 for submdoule a, while it wants to\n> checkout d_2 for d. It can be achieved by using [-ca|--customized-argument].\n\nRead this again, notice \"for the same example mentioned above\", and go\n\"Huh?\"\n\n> This results the script to prompt for user input, which will be passed as\n> argument to the command for that module.\n> \tgit submodule recurse -ca checkout\n> \tWorking in mod a .......\n> \tPlease provide arguments for this module: a_1\n> \tWorking in mod d .......\n> \tPlease provide arguments for this module: a_1\n\nAgain, a blank line before the displayed script like this would make it\neasier to read.\n\nA single dash with two letters for an option name is somewhat\nunconventional.  Shouldn't this be called interactive arguments, by the\nway?\n\n> It is usually helpful that when typing a command, being able to see some options\n> come in handy. For example if I can see the available branches before checking\n> out a branch that would be useful, IOW, if one could git branch before git\n> checkout; it is now possible using the [-p|--pre-command] option. Using this\n> command you can actually execute other git commands before specifying the\n> arguments to the original command. E.g. if the above command is changed to,\n> \tgit submodule recurse -ca -p checkout\n> it will prompt the user for the pre command until one is satisfied and later\n> the user can actually use them in the argument.\n\nBtw, can we please try to keep commit log messages readable?\n\nThe above \"blob of text\" could/should have more structure than being just \none big block, and could have been structured as a few shorter paragraphs \nto make it easier to read.\n\nI don't know about you guys, but I read a *lot* of emails (and commit\nmessages), and I hate seeing big blobs of text without structure. Give it\na few breaks to make it easier to read, like just making new paragraphs,\ni.e. something like:\n\n> When typing a command, being able to see some options come in handy.\n> For example, if a command asks for an option to \"git checkout\", being\n> able to run \"git branch\" to see what branches exist before answering\n> might help the user.\n>\n> \"git submodule recurse\" allows this with the [-p|--pre-command]\n> option. With this option, you can actually execute other git commands\n> before specifying the arguments to the original command. E.g. if the\n> above command is changed to:\n>\n>     git submodule recurse -ca -p checkout\n>\n> it will prompt the user for the pre command until one is satisfied and\n> later the user can actually use them in the argument.\n\nand now you have a bit of a breather space and some visual cues for where\nyou are in the text.\n\nYeah, maybe it's just me, but I like my whitespace. Ihaveareallyhardtime\nreadingtextthatdoesn'thavethepropermarkersforwhereconceptsstartandbegin, \nandthatreallydoesincludetheverticalwhitespacetoo.\n\nBy the way, I do not find your example particularly convincing.\n\n> +do_pre_command()\n> +{\n> +\tsay \"Starting pre-comamnd execution!\"\n> +\twhile :\n> +\tdo\n> +\t\t(\n> +\t\t\tread -p \"Please provide a git command: \" pre_command\n\n\"read -p\"?  That's not even in POSIX.  Please don't.\n\n> +\t\t\ttest -z \"$pre_command\" || git \"$pre_command\"\n\nI am not convinced.  Why do you limit it only to a git command?  Why do\nyou limit it only to a git command that does not take any parameters?  How\nis this more useful over \\C-z and returning to a shell, or examining the\nsituation in a different window/screen?\n\n> +}\n> +\n> +# Take arguments from user to pass as custom arguments\n> +get_custom_args()\n> +{\n> +\tread -p \"Please provide arguments for this module: \" custom_args\n> +}\n\nContrary to its name, it reads a _single_ argument,...\n\n>  # Initializes the submodule if already not initialized\n>  # and auto initialize is enabled\n>  initialize_sub_module()\n> @@ -460,8 +484,10 @@ traverse_module()\n>  \t\t# pwd is mentioned in order to enable the ser to distinguish\n>  \t\t# between same name modules, e.g. a/lib and b/lib.\n>  \t\tsay \"Working in mod $submod_path\" @ `pwd` \"with $@ ($#)\"\n> +\t\ttest -n \"$pre_cmd\" && do_pre_command\n> +\t\ttest -n \"$use_custom_args\" && get_custom_args\n>  \t\tcmd_status=\n> -\t\tgit \"$@\" || cmd_status=1\n> +\t\tgit \"$@\" \"$custom_args\" || cmd_status=1\n\n... and passes it as a single argument.\n\nThe overall structure of recursing into and running arbitrary commands\ninside each submodule might be useful, but the implementation feels rather\ntoo limiting.\n\nCome to think of it, does it really matter that the command you run by\nrecursing into them is limited to \"git-foo\" command?  I do not see you are\ntaking advantage of it being a git command, so it feels like an arbitrary\nrestriction to me, too.\n\n"},{"id":"71223","messageId":"7vfxv49lr7.fsf@gitster.siamese.dyndns.org","threadId":"12532","inReplyTo":"1204788817-22720-1-git-send-email-imyousuf@gmail.com","subject":"Re: [PATCH] - Added command synopsis in code and edited them in manual","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-06T10:42:36Z","receivedAt":"2008-03-06T10:42:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"imyousuf@gmail.com writes:\n\n> From: Imran M Yousuf <imyousuf@smartitengineering.com>\n>\n> Added the command synopsis so that they are available for\n> any future command additions.\n\nI think you are talking about the comments you added at the beginning of\nthe script; I do not particularly see it as improvement.  Rather, it\nis just an additional maintenance burden that risks going out of sync with\nthe documentation.\n\nIt may make more sense to make your added lines into one line per\nsubcommand descriptions in LONG_USAGE, and shorten USAGE to just mention\n\"git submodule <command> <options>\".  The command is multi-featured enough\nthat it can afford to have a long on-line usage text, and I am reasonably\nsure you would agree with me if you read your later patches that cram tons\nof options on a single line USAGE.  It simply is unreadable, no matter how\nwide your terminal is.\n\nBy the way, please use imperative, e.g. \"Add gostak so that doshes are\nproperly distimmed\", instead of past tense \"Added synopsis\".\n\n> In the init/update command synopsis either of them is required\n> command as is add in its synopsis, so removed the square brackets\n> around them from the documentation\n\nBut without grouping, the reader cannot tell where the alternation begins\nand ends.  Typically we use () in our documentation set.\n\nThat reminds me of the topic of marking \"either this or that, you must\nhave one\" with { this | that }, and that is more in line with other\nsystems' documentation, and is also consistent with what POSIX recommends.\nI think the list atmosphere back then was \"Yeah, {} may be more kosher,\nbut we have been consistently using () and that is not misleading, so\nunless we convert everything consistently, using {} at only a few places\nmakes it even worse.\"  I personally do not mind patches to convert\neverybody to {} if we are confident that we can finish it before -rc1.\n"}]}