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

[PATCH v2 4/5] git-submodule.sh: Add pre command argument to git submodule recurse subcommand

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

I usually feel 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 I could do 'git branch' before git checkout it would be helpful.

It is now possible using the [-p|--pre-command] option. Using this subcommand command argument one can actually execute another command before specifying the arguments or the original command getting executed.

	git submodule recurse -a -p checkout

it will prompt the user for the pre command until one is satisfied and later the original command with the custom argument will get executed.

Signed-off-by: Imran M Yousuf <imyousuf@smartitengineering.com>
---
 git-submodule.sh |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 314652d..dd80850 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] [-a|--customized-argument] <git command> [<args> ...]"
+$0 recurse [-q|--quiet] [-e|--exit-after-error] [-d|--depth <recursion depth>] [-b|--breadth-first] [-a|--customized-argument] [-p|--pre-command] <git command> [<args> ...]"
 OPTIONS_SPEC=
 . git-sh-setup
 require_work_tree
@@ -27,6 +27,7 @@ depth_first=1
 on_error=
 use_custom_args=
 custom_args=
+pre_cmd=
 
 #
 # print stuff on stdout unless -q was specified
@@ -587,6 +588,28 @@ cmd_status()
 	done
 }
 
+# Take command from user and execute it until user wants to discontinue
+do_pre_command()
+{
+	say "Starting pre-comamnd execution!"
+	while :
+	do
+		(
+			printf "Please provide a command: "
+			read pre_command
+			test -z "$pre_command" ||
+			eval "$pre_command"
+		)
+		printf "Press y to continue with another shell command... "
+		read keypress
+		if test "$keypress" != "y" &&
+			test "$keypress" != "Y"
+		then
+			break
+		fi
+	done
+}
+
 # Take arguments from user to pass as custom arguments and execute the command
 exec_with_custom_args()
 {
@@ -673,6 +696,7 @@ 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 "$@"
+		test -n "$pre_cmd" && do_pre_command
 		say "git submodule recurse $submod_path $*"
 		if test -n "$use_custom_args"
 		then
@@ -734,6 +758,9 @@ cmd_recurse() {
 		-a|--customized-argument)
 			use_custom_args=1
 			;;
+		-p|--pre-command)
+			pre_cmd=1
+			;;
 		-*)
 			usage
 			;;
-- 
1.5.4.2
Previous: imyousuf@gmail.comNext: imyousuf@gmail.com
Message 4 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.