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 <redacted>
---
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
Hi,
On Thu, 17 Jul 2008, Nigel Magnay wrote:
When doing a git submodule update, it fetches any missing submodule
commits from the repository specified in .gitmodules.
Huh? It takes what is in .git/config! Not what is in .gitmodules.
So if you have another remote (or URL, e.g. if you have ssh:// access, but
the .gitmodules file lists git://), just edit .git/config.
I meant, that is the whole _point_ of having a two-step init/update
procedure.
Ciao,
Dscho
On Thu, Jul 17, 2008 at 01:08:19PM +0100, Nigel Magnay wrote:
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 <redacted>
I don't think it is good idea to hijack git submodule update for this.
This command has a specific purpose:
"When I pulled new version of the main tree, bring my
submodule checkouts in line with whatever is specified
within the new tree revision."
Your usage scenario has nothing to do with that, it is about "batch
manipulation" of all the submodules at once in a certain way. I think
using the same command for two conceptually pretty much unrelated
purposes will only clutter up the UI, and we should think of a better
general interface pattern for these operations.
In the new git-submodule description, it is said that
"This command will manage the tree entries and contents of the
gitmodules file for you."
and I think we should keep it at this; anything that is related to
submodules, but does not do this directly, would IMHO live better
as some kind of "submodule-recursive" extension of other existing
commands. Say, would this particular need of yours be served by a
hypothetical command like
git checkout --submodules nifty
to check out branch nifty of all submodules or am I misunderstanding
what are you trying to achieve?
If not, then actually even _much_ more elegant solution for this
particular problem would be to store submodule.*.branch in .gitmodules
appropriate to the -b parameter of git submodule add. Then, in branch
'nifty' of the main project, you would set submodule.*.branch to 'nifty'
too. Then, in order to bring all the submodules to the latest version,
I could imagine something like
git pull --submodules
(and possibly just abort at the first sight of a conflict, for
starters).
Let's figure up some UI that is nifty and clean. ;-)
--
Petr "Pasky" Baudis
GNU, n. An animal of South Africa, which in its domesticated state
resembles a horse, a buffalo and a stag. In its wild condition it is
something like a thunderbolt, an earthquake and a cyclone. -- A. Pierce