From: Mark Levedahl <mlevedahl@gmail.com>
To: gitster@pobox.org
Cc: git@vger.kernel.org, Mark Levedahl <mlevedahl@gmail.com>
Subject: [PATCH 4/7] git-submodule - Possibly inherit parent's default remote on init/clone
Date: Sun, 3 Feb 2008 12:20:46 -0500 [thread overview]
Message-ID: <1202059249-3532-5-git-send-email-mlevedahl@gmail.com> (raw)
In-Reply-To: <1202059249-3532-4-git-send-email-mlevedahl@gmail.com>
For submodules defined relative to their parent, it is likely that the
parent's defined default remote is correct for the child as well. This
allows use of remote names other than "origin", important as managed
submodules are typically checked out on a detached head and therefore
submodule-update invokes git-fetch using the default remote. Without this
change, submodules effectively had to have a default remote of "origin."
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
Documentation/git-submodule.txt | 8 +++++---
git-submodule.sh | 20 ++++++++++++++------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index e818e6e..b04b107 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -37,9 +37,11 @@ status::
init::
Initialize the submodules, i.e. register in .git/config each submodule
- name and url found in .gitmodules. The key used in .git/config is
- `submodule.$name.url`. This command does not alter existing information
- in .git/config.
+ name and url found in .gitmodules, along with the default remote origin.
+ For submodules using a relative url, the default remote is inherited
+ from the parent project, for absolute urls the default "origin" is used.
+ The key used in .git/config is submodule.$name.url`. This command does
+ not alter existing information in .git/config.
update::
Update the registered submodules, i.e. clone missing submodules and
diff --git a/git-submodule.sh b/git-submodule.sh
index a6aaf40..bb0d265 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -7,6 +7,7 @@
USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'
OPTIONS_SPEC=
. git-sh-setup
+. git-parse-remote
require_work_tree
command=
@@ -40,9 +41,7 @@ get_repo_base() {
# Resolve relative url by appending to parent's url
resolve_relative_url ()
{
- branch="$(git symbolic-ref HEAD 2>/dev/null)"
- remote="$(git config branch.${branch#refs/heads/}.remote)"
- remote="${remote:-origin}"
+ remote="$(get_default_remote)"
remoteurl="$(git config remote.$remote.url)" ||
die "remote ($remote) does not have a url in .git/config"
url="$1"
@@ -92,6 +91,7 @@ module_clone()
{
path=$1
url=$2
+ origin=$3
# If there already is a directory at the submodule path,
# expect it to be empty (since that is the default checkout
@@ -107,7 +107,7 @@ module_clone()
test -e "$path" &&
die "A file already exist at path '$path'"
- git-clone -n "$url" "$path" ||
+ git-clone -n -o "$origin" "$url" "$path" ||
die "Clone of '$url' into submodule path '$path' failed"
}
@@ -156,10 +156,12 @@ cmd_add()
case "$repo" in
./*|../*)
# dereference source url relative to parent's url
+ origin=$(get_default_remote)
realrepo="$(resolve_relative_url $repo)" ;;
*)
# Turn the source into an absolute path if
# it is local
+ origin=origin
if base=$(get_repo_base "$repo"); then
repo="$base"
fi
@@ -180,7 +182,7 @@ cmd_add()
git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
die "'$path' already exists in the index"
- module_clone "$path" "$realrepo" || exit
+ module_clone "$path" "$realrepo" "$origin" || exit
(unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
die "Unable to checkout submodule '$path'"
git add "$path" ||
@@ -236,9 +238,14 @@ cmd_init()
case "$url" in
./*|../*)
url="$(resolve_relative_url "$url")"
+ origin=$(get_default_remote)
+ ;;
+ *)
+ origin=origin
;;
esac
+ git config submodule."$name".origin "$origin" &&
git config submodule."$name".url "$url" ||
die "Failed to register url for submodule path '$path'"
@@ -287,10 +294,11 @@ cmd_update()
say "Submodule path '$path' not initialized"
continue
fi
+ origin=$(git config submodule."$name".origin || echo origin)
if ! test -d "$path"/.git
then
- module_clone "$path" "$url" || exit
+ module_clone "$path" "$url" "$origin" || exit
subsha1=
else
subsha1=$(unset GIT_DIR; cd "$path" &&
--
1.5.4.18.g43c18
next prev parent reply other threads:[~2008-02-03 17:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-03 17:20 [PATCH 0 of 7] - Improve handling remotes, origin, and submodules Mark Levedahl
2008-02-03 17:20 ` [PATCH 1/7] Teach remote machinery about core.origin config variable Mark Levedahl
2008-02-03 17:20 ` [PATCH 2/7] git-remote - Unset core.origin when deleting the default remote Mark Levedahl
2008-02-03 17:20 ` [PATCH 3/7] git-clone - Set remotes.origin config variable Mark Levedahl
2008-02-03 17:20 ` Mark Levedahl [this message]
2008-02-03 17:20 ` [PATCH 5/7] Teach git-submodule to use top-level remote when updating subprojects Mark Levedahl
2008-02-03 17:20 ` [PATCH 6/7] git-submodule - Allow adding a submodule in-place Mark Levedahl
2008-02-03 17:20 ` [PATCH 7/7] Add t/t7401 - test submodule interaction with remotes machinery Mark Levedahl
-- strict thread matches above, loose matches on Subject: below --
2008-02-03 17:31 [PATCH 0 of 7] [resend] - Improve handling remotes, origin, submodules Mark Levedahl
2008-02-03 17:31 ` [PATCH 1/7] Teach remote machinery about core.origin config variable Mark Levedahl
2008-02-03 17:31 ` [PATCH 2/7] git-remote - Unset core.origin when deleting the default remote Mark Levedahl
2008-02-03 17:31 ` [PATCH 3/7] git-clone - Set remotes.origin config variable Mark Levedahl
2008-02-03 17:31 ` [PATCH 4/7] git-submodule - Possibly inherit parent's default remote on init/clone Mark Levedahl
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=1202059249-3532-5-git-send-email-mlevedahl@gmail.com \
--to=mlevedahl@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).