From: Lars Hjemli <hjemli@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 4/5] git-submodule: give submodules proper names
Date: Mon, 11 Jun 2007 21:12:24 +0200 [thread overview]
Message-ID: <1181589146188-git-send-email-hjemli@gmail.com> (raw)
In-Reply-To: <1181589146685-git-send-email-hjemli@gmail.com>
This changes the way git-submodule uses .gitmodules: Subsections no longer
specify the submodule path, they now specify the submodule name. The
submodule path is found under the new key "submodule.<name>.path", which is
a required key.
With this change a submodule can be moved between different 'checkout paths'
without upsetting git-submodule.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
git-submodule.sh | 45 ++++++++++++++++++++++++++++++-------------
t/t7400-submodule-basic.sh | 20 +++++++++++++++---
2 files changed, 47 insertions(+), 18 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 6c83c52..89a3885 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -25,6 +25,19 @@ say()
fi
}
+#
+# Map submodule path to submodule name
+#
+# $1 = path
+#
+module_name()
+{
+ name=$(GIT_CONFIG=.gitmodules git-config --get-regexp '^submodule\..*\.path$' "$1" |
+ sed -nre 's/^submodule\.(.+)\.path .+$/\1/p')
+ test -z "$name" &&
+ die "No submodule mapping found in .gitmodules for path '$path'"
+ echo "$name"
+}
#
# Clone a submodule
@@ -49,7 +62,7 @@ module_clone()
die "A file already exist at path '$path'"
git-clone -n "$url" "$path" ||
- die "Clone of submodule '$path' failed"
+ die "Clone of '$url' into submodule path '$path' failed"
}
#
@@ -63,17 +76,18 @@ modules_init()
while read mode sha1 stage path
do
# Skip already registered paths
- url=$(git-config submodule."$path".url)
+ name=$(module_name "$path") || exit
+ url=$(git-config submodule."$name".url)
test -z "$url" || continue
- url=$(GIT_CONFIG=.gitmodules git-config submodule."$path".url)
+ url=$(GIT_CONFIG=.gitmodules git-config submodule."$name".url)
test -z "$url" &&
- die "No url found for submodule '$path' in .gitmodules"
+ die "No url found for submodule path '$path' in .gitmodules"
- git-config submodule."$path".url "$url" ||
- die "Failed to register url for submodule '$path'"
+ git-config submodule."$name".url "$url" ||
+ die "Failed to register url for submodule path '$path'"
- say "Submodule '$path' registered with url '$url'"
+ say "Submodule '$name' ($url) registered for path '$path'"
done
}
@@ -87,13 +101,14 @@ modules_update()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
- url=$(git-config submodule."$path".url)
+ name=$(module_name "$path") || exit
+ url=$(git-config submodule."$name".url)
if test -z "$url"
then
# Only mention uninitialized submodules when its
# path have been specified
test "$#" != "0" &&
- say "Submodule '$path' not initialized"
+ say "Submodule path '$path' not initialized"
continue
fi
@@ -104,22 +119,22 @@ modules_update()
else
subsha1=$(unset GIT_DIR && cd "$path" &&
git-rev-parse --verify HEAD) ||
- die "Unable to find current revision of submodule '$path'"
+ die "Unable to find current revision in submodule path '$path'"
fi
if test "$subsha1" != "$sha1"
then
(unset GIT_DIR && cd "$path" && git-fetch &&
git-checkout -q "$sha1") ||
- die "Unable to checkout '$sha1' in submodule '$path'"
+ die "Unable to checkout '$sha1' in submodule path '$path'"
- say "Submodule '$path': checked out '$sha1'"
+ say "Submodule path '$path': checked out '$sha1'"
fi
done
}
#
-# List all registered submodules, prefixed with:
+# List all submodules, prefixed with:
# - submodule not initialized
# + different revision checked out
#
@@ -133,7 +148,9 @@ modules_list()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
- if ! test -d "$path"/.git
+ name=$(module_name "$path") || exit
+ url=$(git-config submodule."$name".url)
+ if test -z "url" || ! test -d "$path"/.git
then
say "-$sha1 $path"
continue;
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 9f2d4f9..7a9b505 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -18,7 +18,7 @@ subcommands of git-submodule.
# -add directory lib to 'superproject', this creates a DIRLINK entry
# -add a couple of regular files to enable testing of submodule filtering
# -mv lib subrepo
-# -add an entry to .gitmodules for path 'lib'
+# -add an entry to .gitmodules for submodule 'example'
#
test_expect_success 'Prepare submodule testing' '
mkdir lib &&
@@ -40,7 +40,19 @@ test_expect_success 'Prepare submodule testing' '
git-add a lib z &&
git-commit -m "super commit 1" &&
mv lib .subrepo &&
- GIT_CONFIG=.gitmodules git-config submodule.lib.url git://example.com/lib.git
+ GIT_CONFIG=.gitmodules git-config submodule.example.url git://example.com/lib.git
+'
+
+test_expect_success 'status should fail for unmapped paths' '
+ if git-submodule status
+ then
+ echo "[OOPS] submodule status succeeded"
+ false
+ elif ! GIT_CONFIG=.gitmodules git-config submodule.example.path lib
+ then
+ echo "[OOPS] git-config failed to update .gitmodules"
+ false
+ fi
'
test_expect_success 'status should only print one line' '
@@ -54,12 +66,12 @@ test_expect_success 'status should initially be "missing"' '
test_expect_success 'init should register submodule url in .git/config' '
git-submodule init &&
- url=$(git-config submodule.lib.url) &&
+ url=$(git-config submodule.example.url) &&
if test "$url" != "git://example.com/lib.git"
then
echo "[OOPS] init succeeded but submodule url is wrong"
false
- elif ! git-config submodule.lib.url ./.subrepo
+ elif ! git-config submodule.example.url ./.subrepo
then
echo "[OOPS] init succeeded but update of url failed"
false
--
1.5.2.1.914.gbd3a7
next prev parent reply other threads:[~2007-06-11 19:10 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-11 19:12 [PATCH 0/5] misc. submodule related changes Lars Hjemli
2007-06-11 19:12 ` [PATCH 1/5] t7400: barf if git-submodule removes or replaces a file Lars Hjemli
2007-06-11 19:12 ` [PATCH 2/5] git-submodule: remember to checkout after clone Lars Hjemli
2007-06-11 19:12 ` [PATCH 3/5] Rename sections from "module" to "submodule" in .gitmodules Lars Hjemli
2007-06-11 19:12 ` Lars Hjemli [this message]
2007-06-11 19:12 ` [PATCH 5/5] Add gitmodules(5) Lars Hjemli
2007-06-11 22:59 ` Frank Lichtenheld
2007-06-12 7:05 ` Lars Hjemli
2007-06-12 8:04 ` Sven Verdoolaege
2007-06-12 8:27 ` Lars Hjemli
2007-06-12 9:45 ` Josef Weidendorfer
2007-06-12 10:23 ` Lars Hjemli
2007-06-12 12:05 ` Josef Weidendorfer
2007-06-12 9:49 ` Sven Verdoolaege
2007-06-12 10:28 ` Lars Hjemli
2007-06-12 10:34 ` Johannes Sixt
2007-06-12 10:48 ` Johannes Sixt
[not found] ` <8c5c35580706120352y24e53a10sf339147b22f1286e@mail.gmail.com>
2007-06-12 10:54 ` Lars Hjemli
2007-06-12 11:03 ` Johannes Sixt
2007-06-12 11:12 ` Lars Hjemli
2007-06-12 12:23 ` Josef Weidendorfer
2007-06-12 12:37 ` Lars Hjemli
2007-06-12 12:41 ` Johannes Sixt
2007-06-12 13:40 ` Josef Weidendorfer
2007-06-12 13:50 ` Josef Weidendorfer
2007-06-12 19:03 ` Junio C Hamano
2007-06-12 19:10 ` Sven Verdoolaege
2007-06-12 21:33 ` Josef Weidendorfer
-- strict thread matches above, loose matches on Subject: below --
2007-06-11 0:03 [PATCH 4/5] git-submodule: give submodules proper names Lars Hjemli
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=1181589146188-git-send-email-hjemli@gmail.com \
--to=hjemli@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.