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

[PATCH] - Added pre command and custom argument support to git submodule recurse command

From
imyousuf@gmail.com <imyousuf@gmail.com>
Date
Mar 6, 2008, 07:33 UTC
Message-ID
<1204788817-22720-3-git-send-email-imyousuf@gmail.com>
In-Reply-To
<1204788817-22720-2-git-send-email-imyousuf@gmail.com>
From: Imran M Yousuf <imyousuf@smartitengineering.com>
There is one scenario that has been put forward several times in
discussion over the recurse command - it is that commands can have
different arguments for different modules. For example for the same example
mentioned above, one wants to check a_1 for submdoule a, while it wants to
checkout d_2 for d. It can be achieved by using [-ca|--customized-argument].
This results the script to prompt for user input, which will be passed as
argument to the command for that module.
	git submodule recurse -ca checkout
	Working in mod a .......
	Please provide arguments for this module: a_1
	Working in mod d .......
	Please provide arguments for this module: a_1
It is usually helpful that when typing a command, being able to see some options
come in handy. For example if I can see the available branches before checking
out a branch that would be useful, IOW, if one could git branch before git
checkout; it is now possible using the [-p|--pre-command] option. Using this
command you can actually execute other git commands before specifying the
arguments to the original command. E.g. if the above command is changed to,
	git submodule recurse -ca -p checkout
it will prompt the user for the pre command until one is satisfied and later
the user can actually use them in the argument.

As these two options get along well together it made sense to me to group them together.

Signed-off-by: Imran M Yousuf <imyousuf@smartitengineering.com>
---
 git-submodule.sh |   33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index ee3c928..05fd1d2 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -8,8 +8,8 @@
 # git-submodule [-q|--quiet] add [-b|--branch branch] <repository> [<path>]
 # git-submodule [-q|--quiet] [status] [-c|--cached] [--] [<path>...]
 # git-submodule [-q|--quiet] init|update [--] [<path>...]
-# git-submodule [-q|--quiet] recurse [-i|--initialize] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-df|--depth-first] <command> [<arguments> ...]
-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> ...]]'
+# 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> ...]
+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> ...]]'
 OPTIONS_SPEC=
 . git-sh-setup
 require_work_tree
@@ -392,6 +392,30 @@ cmd_status()
 	done
 }
 
+do_pre_command()
+{
+	say "Starting pre-comamnd execution!"
+	while :
+	do
+		(
+			read -p "Please provide a git command: " pre_command
+			test -z "$pre_command" || git "$pre_command"
+		)
+		read -p "Press y to continue with another git command... " keypress
+		if test "$keypress" != "y" &&
+			test "$keypress" != "Y"
+		then
+			break
+		fi
+	done
+}
+
+# Take arguments from user to pass as custom arguments
+get_custom_args()
+{
+	read -p "Please provide arguments for this module: " custom_args
+}
+
 # Initializes the submodule if already not initialized
 # and auto initialize is enabled
 initialize_sub_module()
@@ -460,8 +484,10 @@ traverse_module()
 		# pwd is mentioned in order to enable the ser to distinguish
 		# between same name modules, e.g. a/lib and b/lib.
 		say "Working in mod $submod_path" @ `pwd` "with $@ ($#)"
+		test -n "$pre_cmd" && do_pre_command
+		test -n "$use_custom_args" && get_custom_args
 		cmd_status=
-		git "$@" || cmd_status=1
+		git "$@" "$custom_args" || cmd_status=1
 		# 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
@@ -598,4 +624,3 @@ then
 fi
 
 "cmd_$command" "$@"
Previous: imyousuf@gmail.comNext: imyousuf@gmail.com
Message 3 of 8 in “- Added command synopsis in code and edited them in manual”
  1. - Added command synopsis in code and edited them in manualimyousuf@gmail.com, Mar 6, 2008
  2. - Added 'recurse' subcommand to git submoduleimyousuf@gmail.com, Mar 6, 2008
  3. - Added pre command and custom argument support to git submodule recurse commandimyousuf@gmail.com, Mar 6, 2008
  4. - Added pre command and custom argument support to git submodule recurse commandimyousuf@gmail.com, Mar 6, 2008
  5. - Added pre command and custom argument support to git submodule recurse commandimyousuf@gmail.com, Mar 6, 2008
  6. Junio C HamanoMar 6, 2008
  7. Junio C HamanoMar 6, 2008
  8. Junio C HamanoMar 6, 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.