git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Packham <judge.packham@gmail.com>
To: git@vger.kernel.org
Cc: Jens.Lehmann@web.de, Chris Packham <judge.packham@gmail.com>
Subject: [RFC/PATCH] submodule: add 'exec' option to submodule update
Date: Fri, 28 Jun 2013 21:53:10 +1200	[thread overview]
Message-ID: <1372413190-32732-1-git-send-email-judge.packham@gmail.com> (raw)

This allows the user some finer grained control over how the update is
done. The primary motivation for this was interoperability with stgit
however being able to intercept the submodule update process may prove
useful for integrating or extending other tools.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
--
Hi,

At $dayjob we have a number of users that are accustomed to using stgit.
Stgit doesn't play nicely with git rebase which would be the logical
setting for submodule.*.update for our usage. Instead we need to run
'stg rebase --merged' on those submodules that have been initialised
with stgit.

Our current solution is an in-house script which is a poor substitute
for git submodule update. I'd much rather replace our script with git
submodule update but we do have a requirement to keep stgit for the
foreseeable future.  Rather than narrowing in on stgit it seems logical
to allow an arbitrary update command to be executed.
---
 Documentation/git-submodule.txt |  8 +++++++-
 git-submodule.sh                | 22 +++++++++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index e576713..a0d8b89 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -16,7 +16,7 @@ SYNOPSIS
 'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
 	      [-f|--force] [--rebase] [--reference <repository>]
-	      [--merge] [--recursive] [--] [<path>...]
+	      [--merge] [--recursive] [--exec <command>] [--] [<path>...]
 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
 	      [commit] [--] [<path>...]
 'git submodule' [--quiet] foreach [--recursive] <command>
@@ -172,6 +172,12 @@ If `--force` is specified, the submodule will be checked out (using
 `git checkout --force` if appropriate), even if the commit specified in the
 index of the containing repository already matches the commit checked out in
 the submodule.
++
+If `--exec` is specified the next argument is an arbitrary shell command that
+can be used to gain finer control over how the update is done or integrate with
+external tools. The command should take one argument namely the sha1 of the
+commit to update to. The config variable `submodule.$name.update` can be set
+to `exec` along with `submodule.$name.update.command`.
 
 summary::
 	Show commit summary between the given commit (defaults to HEAD) and
diff --git a/git-submodule.sh b/git-submodule.sh
index eb58c8e..44631c8 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -9,7 +9,7 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re
    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] init [--] [<path>...]
    or: $dashless [--quiet] deinit [-f|--force] [--] <path>...
-   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
+   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--exec <command>] [--] [<path>...]
    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
    or: $dashless [--quiet] foreach [--recursive] <command>
    or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
@@ -32,6 +32,7 @@ nofetch=
 update=
 prefix=
 custom_name=
+update_exec_command=
 
 # The function takes at most 2 arguments. The first argument is the
 # URL that navigates to the submodule origin repo. When relative, this URL
@@ -677,6 +678,12 @@ cmd_update()
 		--checkout)
 			update="checkout"
 			;;
+		--exec)
+			case "$2" in '') usage ;; esac
+			update="exec"
+			update_exec_command="$2"
+			shift
+			;;
 		--)
 			shift
 			break
@@ -718,6 +725,11 @@ cmd_update()
 			update_module=$(git config submodule."$name".update)
 		fi
 
+		if test -z "$update_exec_command"
+		then
+			exec_command=$(git config submodule."$name".update.command)
+		fi
+
 		if test "$update_module" = "none"
 		then
 			echo "Skipping submodule '$prefix$sm_path'"
@@ -799,6 +811,14 @@ Maybe you want to use 'update --init'?")"
 				say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': merged in '\$sha1'")"
 				must_die_on_failure=yes
 				;;
+			exec)
+				test -n "$exec_command" || \
+					die "$(eval_gettext "Unable to update '\$prefix\$sm_path' exec command not specified")"
+				command="$exec_command"
+				die_msg="$(eval_gettext "Unable to exec '\$command \$sha1' in submodule path '\$prefix\$sm_path'")"
+				say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': '\$command \$sha1'")"
+				must_die_on_failure=yes
+				;;
 			*)
 				command="git checkout $subforce -q"
 				die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$prefix\$sm_path'")"
-- 
1.8.3.1.643.gebeea52.dirty

             reply	other threads:[~2013-06-28  9:53 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-28  9:53 Chris Packham [this message]
2013-06-28 10:13 ` [RFC/PATCH] submodule: add 'exec' option to submodule update Stefan Näwe
2013-06-28 10:42 ` Fredrik Gustafsson
2013-06-29  9:11   ` Chris Packham
2013-06-30 15:30     ` Jens Lehmann
2013-07-01  9:21       ` Chris Packham
2013-07-01 10:11       ` [RFC/PATCHv2] submodule: add ability to configure update command Chris Packham
2013-07-01 16:26         ` Junio C Hamano
2013-07-02 10:12           ` [RFC/PATCHv3] submodule update: allow custom " Chris Packham
2013-07-02 16:56             ` Jens Lehmann
2013-07-02 23:26               ` Chris Packham
2013-07-03  6:55                 ` Jens Lehmann
2013-07-03  7:54                   ` Chris Packham
2013-07-03  8:50                     ` Chris Packham
2013-07-03 17:09                       ` Junio C Hamano
2013-07-03  9:02               ` [RFC/PATCHv4] " Chris Packham
2013-07-03 17:17                 ` Junio C Hamano
2013-07-01 16:48         ` [RFC/PATCHv2] submodule: add ability to configure " Junio C Hamano
2013-07-02  9:59           ` Chris Packham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1372413190-32732-1-git-send-email-judge.packham@gmail.com \
    --to=judge.packham@gmail.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).