summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d57dd25)
raw | patch | inline | side by side (parent: d57dd25)
author | Lars Hjemli <hjemli@gmail.com> | |
Mon, 11 Jun 2007 19:12:24 +0000 (21:12 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 12 Jun 2007 08:06:21 +0000 (01:06 -0700) |
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-submodule.sh | patch | blob | history | |
t/t7400-submodule-basic.sh | patch | blob | history |
diff --git a/git-submodule.sh b/git-submodule.sh
index 6c83c52cf422d44fd22b1df4e55da0de5e368581..89a388535026258d65ecba3c0dd6de68e2b06cb4 100755 (executable)
--- a/git-submodule.sh
+++ b/git-submodule.sh
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
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"
}
#
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
}
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
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
#
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;
index 9f2d4f9b38f199c04fb44d13d65659b1ff161d82..7a9b505b13f60ebbca188439b24f7a20b30b66cf 100755 (executable)
# -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 &&
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' '
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