git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/5] git-submodule.sh: Add Custom argument input support to git submodule recurse subcommand

From
imyousuf@gmail.com <imyousuf@gmail.com>
Date
May 5, 2008, 09:09 UTC
Message-ID
<1209978582-5785-3-git-send-email-imyousuf@gmail.com>
In-Reply-To
<1209978582-5785-2-git-send-email-imyousuf@gmail.com>
From: Imran M Yousuf <imyousuf@smartitengineering.com>

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@smartitengineering.com>
---
 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
Previous: imyousuf@gmail.comNext: imyousuf@gmail.com
Message 3 of 13 in “git-submodule.sh: Add Long Usage instead of simple usage”
  1. 1/5 git-submodule.sh: Add Long Usage instead of simple usageimyousuf@gmail.com, May 5, 2008
  2. 2/5 git-submodule.sh: Add recurse subcommand with basic optionsimyousuf@gmail.com, May 5, 2008
  3. 3/5 git-submodule.sh: Add Custom argument input support to git submodule recurse subcommandimyousuf@gmail.com, May 5, 2008
  4. 4/5 git-submodule.sh: Add pre command argument to git submodule recurse subcommandimyousuf@gmail.com, May 5, 2008
  5. 5/5 Documentation/git-submodule.txt: Add documentation for the recurse subcommandimyousuf@gmail.com, May 5, 2008
  6. Junio C HamanoMay 12, 2008
  7. Johan HerlandMay 18, 2008
  8. Sverre RabbelierMay 18, 2008
  9. Johannes SchindelinMay 18, 2008
  10. Sverre RabbelierMay 18, 2008
  11. Imran M YousufMay 19, 2008
  12. Junio C HamanoMay 12, 2008
  13. Imran M YousufMay 13, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.