git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nigel Magnay" <nigel.magnay@gmail.com>
To: "Git Mailing List" <git@vger.kernel.org>
Subject: [PATCH] Teach git submodule update to use distributed repositories
Date: Thu, 17 Jul 2008 13:08:19 +0100	[thread overview]
Message-ID: <320075ff0807170508j3d3c1ef8j49df576fc47debe2@mail.gmail.com> (raw)

When doing a git submodule update, it fetches any missing submodule
commits from the repository specified in .gitmodules. If you instead
want to pull from another repository, you currently need to do a fetch
in each submodule by hand.

Signed-off-by: Nigel Magnay <nigel.magnay@gmail.com>
---
This is my first attempt at adding things to help everyday usage of
git submodule.

I don't usually write much shell script; and it's my first patch, so
it's possible there are better ways to do these things..

 git-submodule.sh |   33 +++++++++++++++++++++++++++++++--
 1 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 9228f56..40e1aa1 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -5,7 +5,7 @@
 # Copyright (c) 2007 Lars Hjemli

 USAGE="[--quiet] [--cached] \
-[add <repo> [-b branch] <path>]|[status|init|update
[-i|--init]|summary [-n|--summary-limit <n>] [<commit>]] \
+[add <repo> [-b branch] <path>]|[status|init|update [-i|--init]
[-o|--origin <repository>] [-r|-refspec <refspec>]|summary
[-n|--summary-limit <n>] [<commit>]] \
 [--] [<path>...]"
 OPTIONS_SPEC=
 . git-sh-setup
@@ -15,6 +15,8 @@ command=
 branch=
 quiet=
 cached=
+repository=
+refspec=

 #
 # print stuff on stdout unless -q was specified
@@ -270,6 +272,14 @@ cmd_update()
 			shift
 			cmd_init "$@" || return
 			;;
+		-o|--origin)
+			shift
+			repository=$1
+			;;
+		-r|--refspec)
+			shift
+			refspec=$1
+			;;
 		--)
 			shift
 			break
@@ -311,7 +321,9 @@ cmd_update()

 		if test "$subsha1" != "$sha1"
 		then
-			(unset GIT_DIR; cd "$path" && git-fetch &&
+			set_submodule_repository "$repository" "$path"
+
+			(unset GIT_DIR; cd "$path" && git-fetch "$subrepo" "$refspec" &&
 				git-checkout -q "$sha1") ||
 			die "Unable to checkout '$sha1' in submodule path '$path'"

@@ -320,6 +332,23 @@ cmd_update()
 	done
 }

+#
+# If we asked for a repository such as 'origin', just pass this through
+# otherwise, try to calculate what the repository URL might be by
+# adding the submodule path to the url, subtracting any /.git first
+#
+set_submodule_repository() {
+
+	if [ -z `echo "$1" | grep '/'` ]
+	then
+		# This is not a URL - just use the name
+		subrepo="$1"
+	else
+		# This is a URL. Chop off /.git if it's there, and add submodule path
+		subrepo="${1/%\/.git/}/$2"
+	fi
+}
+
 set_name_rev () {
 	revname=$( (
 		unset GIT_DIR
-- 
1.5.6.2

             reply	other threads:[~2008-07-17 12:09 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-17 12:08 Nigel Magnay [this message]
2008-07-17 12:13 ` [PATCH] Teach git submodule update to use distributed repositories Johannes Schindelin
     [not found]   ` <320075ff0807170520r200e546ejbad2ed103bd65f82@mail.gmail.com>
2008-07-17 12:21     ` Nigel Magnay
2008-07-17 12:58       ` Johannes Schindelin
2008-07-17 14:03         ` Nigel Magnay
2008-07-17 14:16           ` Johannes Schindelin
2008-07-17 15:07             ` Nigel Magnay
2008-07-17 18:22               ` Petr Baudis
2008-07-18  8:11                 ` Nigel Magnay
2008-07-18  8:45                   ` Jakub Narebski
2008-07-18  9:00                     ` Junio C Hamano
2008-07-18  9:07                       ` Jakub Narebski
2008-07-18  9:18                         ` Nigel Magnay
2008-07-18  9:16                   ` Petr Baudis
2008-07-18  9:36                     ` Nigel Magnay
2008-07-18 10:00                       ` Petr Baudis
2008-07-18 11:20                         ` Nigel Magnay
2008-07-18 14:43                           ` Petr Baudis
2008-07-18 15:09                             ` Nigel Magnay
2008-07-18 15:49                               ` Petr Baudis
2008-07-18 22:38                                 ` Mark Levedahl
2008-07-21 10:59                                 ` Nigel Magnay
2008-07-17 14:38 ` Petr Baudis

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=320075ff0807170508j3d3c1ef8j49df576fc47debe2@mail.gmail.com \
    --to=nigel.magnay@gmail.com \
    --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).