* [PATCH 4/5] git-submodule: give submodules proper names
@ 2007-06-11 0:03 Lars Hjemli
0 siblings, 0 replies; 2+ messages in thread
From: Lars Hjemli @ 2007-06-11 0:03 UTC (permalink / raw)
To: git@vger.kernel.org
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH 0/5] misc. submodule related changes
@ 2007-06-11 19:12 Lars Hjemli
2007-06-11 19:12 ` [PATCH 1/5] t7400: barf if git-submodule removes or replaces a file Lars Hjemli
0 siblings, 1 reply; 2+ messages in thread
From: Lars Hjemli @ 2007-06-11 19:12 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Here is a reworked patch-series for git-submodule, trying to cater for
the issues with the previous series.
Shortlog:
[1/5] t7400: barf if git-submodule removes or replaces a file
[2/5] git-submodule: remember to checkout after clone
[3/5] Rename sections from "module" to "submodule" in .gitmodules
[4/5] git-submodule: give submodules proper names
[5/5] Add gitmodules(5)
Diffstat:
Documentation/Makefile | 2 +-
Documentation/gitmodules.txt | 63 ++++++++++++++++++++++++++++++++++++++++++
git-submodule.sh | 52 +++++++++++++++++++++++-----------
t/t7400-submodule-basic.sh | 22 +++++++++++---
4 files changed, 116 insertions(+), 23 deletions(-)
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 1/5] t7400: barf if git-submodule removes or replaces a file
2007-06-11 19:12 [PATCH 0/5] misc. submodule related changes Lars Hjemli
@ 2007-06-11 19:12 ` Lars Hjemli
2007-06-11 19:12 ` [PATCH 2/5] git-submodule: remember to checkout after clone Lars Hjemli
0 siblings, 1 reply; 2+ messages in thread
From: Lars Hjemli @ 2007-06-11 19:12 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
The test for an unmolested file wouldn't fail properly if the file had been
removed or replaced by something other than a regular file. This fixes it.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
t/t7400-submodule-basic.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 3940433..74fafce 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -72,7 +72,7 @@ test_expect_success 'update should fail when path is used by a file' '
then
echo "[OOPS] update should have failed"
false
- elif test -f lib && test "$(cat lib)" != "hello"
+ elif test "$(cat lib)" != "hello"
then
echo "[OOPS] update failed but lib file was molested"
false
--
1.5.2.1.914.gbd3a7
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/5] git-submodule: remember to checkout after clone
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 ` Lars Hjemli
2007-06-11 19:12 ` [PATCH 3/5] Rename sections from "module" to "submodule" in .gitmodules Lars Hjemli
0 siblings, 1 reply; 2+ messages in thread
From: Lars Hjemli @ 2007-06-11 19:12 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
After the initial clone of a submodule, no files would be checked out in
the submodule directory if the submodule HEAD was equal to the SHA-1
specified in the index of the containing repository. This fixes the problem
by simply ignoring submodule HEAD for a fresh clone.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
git-submodule.sh | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 8bdd99a..4a6d64d 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -100,12 +100,13 @@ modules_update()
if ! test -d "$path"/.git
then
module_clone "$path" "$url" || exit
+ subsha1=
+ else
+ subsha1=$(unset GIT_DIR && cd "$path" &&
+ git-rev-parse --verify HEAD) ||
+ die "Unable to find current revision of submodule '$path'"
fi
- subsha1=$(unset GIT_DIR && cd "$path" &&
- git-rev-parse --verify HEAD) ||
- die "Unable to find current revision of submodule '$path'"
-
if test "$subsha1" != "$sha1"
then
(unset GIT_DIR && cd "$path" && git-fetch &&
--
1.5.2.1.914.gbd3a7
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 3/5] Rename sections from "module" to "submodule" in .gitmodules
2007-06-11 19:12 ` [PATCH 2/5] git-submodule: remember to checkout after clone Lars Hjemli
@ 2007-06-11 19:12 ` Lars Hjemli
2007-06-11 19:12 ` [PATCH 4/5] git-submodule: give submodules proper names Lars Hjemli
0 siblings, 1 reply; 2+ messages in thread
From: Lars Hjemli @ 2007-06-11 19:12 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On 6/10/07, Junio C Hamano <gitster@pobox.com> wrote:
> "Lars Hjemli" <hjemli@gmail.com> writes:
>
> > Hmm, maybe I should just rename [module] to [submodule] right now? It
> > would be better forward compatible with the proposed extension, it
> > would 'harmonize' the section names used in .gitmodules and
> > .git/config, and it would offer a clean break from what's currently
> > supported in 'master'.
>
> Yes, the difference between '[submodule]' vs '[module]' in
> .git/config and .gitmodules confused me while looking at your
> latest patch series. I am in favor of unifying them. We would
> not be breaking any released version if we harmonize them now.
Here it is.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
git-submodule.sh | 2 +-
t/t7400-submodule-basic.sh | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 4a6d64d..6c83c52 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -66,7 +66,7 @@ modules_init()
url=$(git-config submodule."$path".url)
test -z "$url" || continue
- url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
+ url=$(GIT_CONFIG=.gitmodules git-config submodule."$path".url)
test -z "$url" &&
die "No url found for submodule '$path' in .gitmodules"
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 74fafce..9f2d4f9 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -40,7 +40,7 @@ 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 module.lib.url git://example.com/lib.git
+ GIT_CONFIG=.gitmodules git-config submodule.lib.url git://example.com/lib.git
'
test_expect_success 'status should only print one line' '
--
1.5.2.1.914.gbd3a7
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 4/5] git-submodule: give submodules proper names
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
0 siblings, 0 replies; 2+ messages in thread
From: Lars Hjemli @ 2007-06-11 19:12 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-06-11 19:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-11 0:03 [PATCH 4/5] git-submodule: give submodules proper names Lars Hjemli
-- strict thread matches above, loose matches on Subject: below --
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 ` [PATCH 4/5] git-submodule: give submodules proper names Lars Hjemli
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).