* [PATCH 0/2] git-submodule: make it easier to use alternate urls
@ 2007-06-05 9:29 Lars Hjemli
[not found] ` <863f2ca67857bc2d09f46f1a5ef6f653d16d5256.1181034736.git.hjemli@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Lars Hjemli @ 2007-06-05 9:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This patch-series teaches git-submodule to register submodule urls in
.git/config during 'git-submodule init' and to perform the actual cloning
during 'git-submodule update', using the url stored in .git/config. So now
the downstream users can specify their preferred urls for each interesting
submodule by editing their .git/config after running 'git-submodule init'.
Documentation/git-submodule.txt | 16 ++++----
git-submodule.sh | 83 ++++++++++++++++++++------------------
t/t7400-submodule-basic.sh | 38 ++++++++++++------
3 files changed, 78 insertions(+), 59 deletions(-)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/2] git-submodule: move cloning into a separate function
[not found] ` <863f2ca67857bc2d09f46f1a5ef6f653d16d5256.1181034736.git.hjemli@gmail.com>
@ 2007-06-05 9:29 ` Lars Hjemli
2007-06-05 10:40 ` Johannes Sixt
[not found] ` <c14730acf8a52a57250303c033ebec09bf960007.1181034736.git.hjemli@gmail.com>
2007-06-06 9:13 ` [PATCH 1/2] git-submodule: move cloning into a separate function Lars Hjemli
2 siblings, 1 reply; 11+ messages in thread
From: Lars Hjemli @ 2007-06-05 9:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This is just a simple refactoring of modules_init() with no change in
functionality.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
git-submodule.sh | 44 ++++++++++++++++++++++++++++----------------
1 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 6ed5a6c..a89ea88 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -25,6 +25,33 @@ say()
fi
}
+
+#
+# Clone a submodule
+#
+module_clone()
+{
+ path=$1
+ url=$2
+
+ # If there already is a directory at the submodule path,
+ # expect it to be empty (since that is the default checkout
+ # action) and try to remove it.
+ # Note: if $path is a symlink to a directory the test will
+ # succeed but the rmdir will fail. We might want to fix this.
+ if test -d "$path"
+ then
+ rmdir "$path" 2>/dev/null ||
+ die "Directory '$path' exist, but is neither empty nor a git repository"
+ fi
+
+ test -e "$path" &&
+ die "A file already exist at path '$path'"
+
+ git-clone -n "$url" "$path" ||
+ die "Clone of submodule '$path' failed"
+}
+
#
# Run clone + checkout on missing submodules
#
@@ -40,20 +67,6 @@ modules_init()
# repository
test -d "$path"/.git && continue
- # If there already is a directory at the submodule path,
- # expect it to be empty (since that is the default checkout
- # action) and try to remove it.
- # Note: if $path is a symlink to a directory the test will
- # succeed but the rmdir will fail. We might want to fix this.
- if test -d "$path"
- then
- rmdir "$path" 2>/dev/null ||
- die "Directory '$path' exist, but is neither empty nor a git repository"
- fi
-
- test -e "$path" &&
- die "A file already exist at path '$path'"
-
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
test -z "$url" &&
die "No url found for submodule '$path' in .gitmodules"
@@ -69,8 +82,7 @@ modules_init()
# logical modulename (if present) as key. But this would need
# another fallback mechanism if the module wasn't named.
- git-clone -n "$url" "$path" ||
- die "Clone of submodule '$path' failed"
+ module_clone "$path" "$url" || exit $?
(unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
die "Checkout of submodule '$path' failed"
--
1.5.2.841.gc9eafb
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] git-submodule: clone during update, not during init
[not found] ` <c14730acf8a52a57250303c033ebec09bf960007.1181034736.git.hjemli@gmail.com>
@ 2007-06-05 9:29 ` Lars Hjemli
2007-06-05 11:18 ` Lars Hjemli
2007-06-06 9:13 ` Lars Hjemli
1 sibling, 1 reply; 11+ messages in thread
From: Lars Hjemli @ 2007-06-05 9:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This teaches 'git-submodule init' to register submodule paths and urls in
.git/config instead of actually cloning them. The cloning is now handled
as part of 'git-submodule update'.
With this change it is possible to specify preferred/alternate urls for
the submodules in .git/config before the submodules are cloned.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
Documentation/git-submodule.txt | 16 +++++++-------
git-submodule.sh | 41 ++++++++++++++++----------------------
t/t7400-submodule-basic.sh | 38 ++++++++++++++++++++++++-----------
3 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index cb0424f..f8fb80f 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -23,15 +23,15 @@ status::
repository. This command is the default command for git-submodule.
init::
- Initialize the submodules, i.e. clone the git repositories specified
- in the .gitmodules file and checkout the submodule commits specified
- in the index of the containing repository. This will make the
- submodules HEAD be detached.
+ Initialize the submodules, i.e. register in .git/config each submodule
+ path and url found in .gitmodules. The key used in git/config is
+ `submodule.$path.url`. This command does not alter existing information
+ in .git/config.
update::
- Update the initialized submodules, i.e. checkout the submodule commits
- specified in the index of the containing repository. This will make
- the submodules HEAD be detached.
+ Update the registered submodules, i.e. clone missing submodules and
+ checkout the commit specified in the index of the containing repository.
+ This will make the submodules HEAD be detached.
OPTIONS
@@ -50,7 +50,7 @@ OPTIONS
FILES
-----
-When cloning submodules, a .gitmodules file in the top-level directory
+When initializing submodules, a .gitmodules file in the top-level directory
of the containing repository is used to find the url of each submodule.
This file should be formatted in the same way as $GIR_DIR/config. The key
to each submodule url is "module.$path.url".
diff --git a/git-submodule.sh b/git-submodule.sh
index a89ea88..e7b6978 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -53,7 +53,7 @@ module_clone()
}
#
-# Run clone + checkout on missing submodules
+# Register submodules in .git/config
#
# $@ = requested paths (default to all)
#
@@ -62,37 +62,23 @@ modules_init()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
- # Skip submodule paths that already contain a .git directory.
- # This will also trigger if $path is a symlink to a git
- # repository
- test -d "$path"/.git && continue
+ # Skip already registered paths
+ url=$(git-config submodule."$path".url)
+ test -z "$url" || continue
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
test -z "$url" &&
die "No url found for submodule '$path' in .gitmodules"
- # MAYBE FIXME: this would be the place to check GIT_CONFIG
- # for a preferred url for this submodule, possibly like this:
- #
- # modname=$(GIT_CONFIG=.gitmodules git-config module."$path".name)
- # alturl=$(git-config module."$modname".url)
- #
- # This would let the versioned .gitmodules file use the submodule
- # path as key, while the unversioned GIT_CONFIG would use the
- # logical modulename (if present) as key. But this would need
- # another fallback mechanism if the module wasn't named.
+ git-config submodule."$path".url "$url" ||
+ die "Failed to register url for submodule '$path'"
- module_clone "$path" "$url" || exit $?
-
- (unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
- die "Checkout of submodule '$path' failed"
-
- say "Submodule '$path' initialized"
+ say "Submodule '$path' registered with url '$url'"
done
}
#
-# Checkout correct revision of each initialized submodule
+# Update each submodule path to correct revision, using clone and checkout as needed
#
# $@ = requested paths (default to all)
#
@@ -101,14 +87,21 @@ modules_update()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
- if ! test -d "$path"/.git
+ url=$(git-config submodule."$path".url)
+ if test -z "$url"
then
# Only mention uninitialized submodules when its
# path have been specified
test "$#" != "0" &&
say "Submodule '$path' not initialized"
- continue;
+ continue
fi
+
+ if ! test -d "$path"/.git
+ then
+ module_clone "$path" "$url" || exit $?
+ fi
+
subsha1=$(unset GIT_DIR && cd "$path" &&
git-rev-parse --verify HEAD) ||
die "Unable to find current revision of submodule '$path'"
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 6274729..3940433 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 ./.subrepo
+ GIT_CONFIG=.gitmodules git-config module.lib.url git://example.com/lib.git
'
test_expect_success 'status should only print one line' '
@@ -52,41 +52,55 @@ test_expect_success 'status should initially be "missing"' '
git-submodule status | grep "^-$rev1"
'
-test_expect_success 'init should fail when path is used by a file' '
+test_expect_success 'init should register submodule url in .git/config' '
+ git-submodule init &&
+ url=$(git-config submodule.lib.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
+ then
+ echo "[OOPS] init succeeded but update of url failed"
+ false
+ fi
+'
+
+test_expect_success 'update should fail when path is used by a file' '
echo "hello" >lib &&
- if git-submodule init
+ if git-submodule update
then
- echo "[OOPS] init should have failed"
+ echo "[OOPS] update should have failed"
false
elif test -f lib && test "$(cat lib)" != "hello"
then
- echo "[OOPS] init failed but lib file was molested"
+ echo "[OOPS] update failed but lib file was molested"
false
else
rm lib
fi
'
-test_expect_success 'init should fail when path is used by a nonempty directory' '
+test_expect_success 'update should fail when path is used by a nonempty directory' '
mkdir lib &&
echo "hello" >lib/a &&
- if git-submodule init
+ if git-submodule update
then
- echo "[OOPS] init should have failed"
+ echo "[OOPS] update should have failed"
false
elif test "$(cat lib/a)" != "hello"
then
- echo "[OOPS] init failed but lib/a was molested"
+ echo "[OOPS] update failed but lib/a was molested"
false
else
rm lib/a
fi
'
-test_expect_success 'init should work when path is an empty dir' '
+test_expect_success 'update should work when path is an empty dir' '
rm -rf lib &&
mkdir lib &&
- git-submodule init &&
+ git-submodule update &&
head=$(cd lib && git-rev-parse HEAD) &&
if test -z "$head"
then
@@ -99,7 +113,7 @@ test_expect_success 'init should work when path is an empty dir' '
fi
'
-test_expect_success 'status should be "up-to-date" after init' '
+test_expect_success 'status should be "up-to-date" after update' '
git-submodule status | grep "^ $rev1"
'
--
1.5.2.841.gc9eafb
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] git-submodule: move cloning into a separate function
2007-06-05 9:29 ` [PATCH 1/2] git-submodule: move cloning into a separate function Lars Hjemli
@ 2007-06-05 10:40 ` Johannes Sixt
2007-06-05 11:13 ` Lars Hjemli
0 siblings, 1 reply; 11+ messages in thread
From: Johannes Sixt @ 2007-06-05 10:40 UTC (permalink / raw)
To: git
Lars Hjemli wrote:
> + module_clone "$path" "$url" || exit $?
Minor nit: The idiom that is commonly used in situations like this (see
other git-* shell scripts):
module_clone "$path" "$url" || exit
because exit without argument uses the code of the last command
executed.
-- Hannes
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/2] git-submodule: move cloning into a separate function
2007-06-05 10:40 ` Johannes Sixt
@ 2007-06-05 11:13 ` Lars Hjemli
2007-06-06 8:55 ` Junio C Hamano
2007-06-17 14:38 ` Sven Verdoolaege
0 siblings, 2 replies; 11+ messages in thread
From: Lars Hjemli @ 2007-06-05 11:13 UTC (permalink / raw)
To: Johannes Sixt; +Cc: git@vger.kernel.org
This is just a simple refactoring of modules_init() with no change in
functionality.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
On Tue, 05 Jun 2007 12:40:50 +0200, Johannes Sixt <J.Sixt@eudaptics.com> wrote:
> Lars Hjemli wrote:
>> + module_clone "$path" "$url" || exit $?
>
> Minor nit: The idiom that is commonly used in situations like this (see
> other git-* shell scripts):
>
> module_clone "$path" "$url" || exit
>
> because exit without argument uses the code of the last command
> executed.
>
Thanks, I'll follow up with matching changes to [patch 2/2].
git-submodule.sh | 44 ++++++++++++++++++++++++++++----------------
1 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 6ed5a6c..a89ea88 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -25,6 +25,33 @@ say()
fi
}
+
+#
+# Clone a submodule
+#
+module_clone()
+{
+ path=$1
+ url=$2
+
+ # If there already is a directory at the submodule path,
+ # expect it to be empty (since that is the default checkout
+ # action) and try to remove it.
+ # Note: if $path is a symlink to a directory the test will
+ # succeed but the rmdir will fail. We might want to fix this.
+ if test -d "$path"
+ then
+ rmdir "$path" 2>/dev/null ||
+ die "Directory '$path' exist, but is neither empty nor a git repository"
+ fi
+
+ test -e "$path" &&
+ die "A file already exist at path '$path'"
+
+ git-clone -n "$url" "$path" ||
+ die "Clone of submodule '$path' failed"
+}
+
#
# Run clone + checkout on missing submodules
#
@@ -40,20 +67,6 @@ modules_init()
# repository
test -d "$path"/.git && continue
- # If there already is a directory at the submodule path,
- # expect it to be empty (since that is the default checkout
- # action) and try to remove it.
- # Note: if $path is a symlink to a directory the test will
- # succeed but the rmdir will fail. We might want to fix this.
- if test -d "$path"
- then
- rmdir "$path" 2>/dev/null ||
- die "Directory '$path' exist, but is neither empty nor a git repository"
- fi
-
- test -e "$path" &&
- die "A file already exist at path '$path'"
-
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
test -z "$url" &&
die "No url found for submodule '$path' in .gitmodules"
@@ -69,8 +82,7 @@ modules_init()
# logical modulename (if present) as key. But this would need
# another fallback mechanism if the module wasn't named.
- git-clone -n "$url" "$path" ||
- die "Clone of submodule '$path' failed"
+ module_clone "$path" "$url" || exit
(unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
die "Checkout of submodule '$path' failed"
--
1.5.2.841.gc9eafb
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] git-submodule: clone during update, not during init
2007-06-05 9:29 ` [PATCH 2/2] git-submodule: clone during update, not during init Lars Hjemli
@ 2007-06-05 11:18 ` Lars Hjemli
0 siblings, 0 replies; 11+ messages in thread
From: Lars Hjemli @ 2007-06-05 11:18 UTC (permalink / raw)
To: Johannes Sixt; +Cc: git
This teaches 'git-submodule init' to register submodule paths and urls in
.git/config instead of actually cloning them. The cloning is now handled
as part of 'git-submodule update'.
With this change it is possible to specify preferred/alternate urls for
the submodules in .git/config before the submodules are cloned.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
Changed from '|| exit @?' to '|| exit'.
Documentation/git-submodule.txt | 16 +++++++-------
git-submodule.sh | 41 ++++++++++++++++----------------------
t/t7400-submodule-basic.sh | 38 ++++++++++++++++++++++++-----------
3 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index cb0424f..f8fb80f 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -23,15 +23,15 @@ status::
repository. This command is the default command for git-submodule.
init::
- Initialize the submodules, i.e. clone the git repositories specified
- in the .gitmodules file and checkout the submodule commits specified
- in the index of the containing repository. This will make the
- submodules HEAD be detached.
+ Initialize the submodules, i.e. register in .git/config each submodule
+ path and url found in .gitmodules. The key used in git/config is
+ `submodule.$path.url`. This command does not alter existing information
+ in .git/config.
update::
- Update the initialized submodules, i.e. checkout the submodule commits
- specified in the index of the containing repository. This will make
- the submodules HEAD be detached.
+ Update the registered submodules, i.e. clone missing submodules and
+ checkout the commit specified in the index of the containing repository.
+ This will make the submodules HEAD be detached.
OPTIONS
@@ -50,7 +50,7 @@ OPTIONS
FILES
-----
-When cloning submodules, a .gitmodules file in the top-level directory
+When initializing submodules, a .gitmodules file in the top-level directory
of the containing repository is used to find the url of each submodule.
This file should be formatted in the same way as $GIR_DIR/config. The key
to each submodule url is "module.$path.url".
diff --git a/git-submodule.sh b/git-submodule.sh
index a89ea88..e7b6978 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -53,7 +53,7 @@ module_clone()
}
#
-# Run clone + checkout on missing submodules
+# Register submodules in .git/config
#
# $@ = requested paths (default to all)
#
@@ -62,37 +62,23 @@ modules_init()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
- # Skip submodule paths that already contain a .git directory.
- # This will also trigger if $path is a symlink to a git
- # repository
- test -d "$path"/.git && continue
+ # Skip already registered paths
+ url=$(git-config submodule."$path".url)
+ test -z "$url" || continue
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
test -z "$url" &&
die "No url found for submodule '$path' in .gitmodules"
- # MAYBE FIXME: this would be the place to check GIT_CONFIG
- # for a preferred url for this submodule, possibly like this:
- #
- # modname=$(GIT_CONFIG=.gitmodules git-config module."$path".name)
- # alturl=$(git-config module."$modname".url)
- #
- # This would let the versioned .gitmodules file use the submodule
- # path as key, while the unversioned GIT_CONFIG would use the
- # logical modulename (if present) as key. But this would need
- # another fallback mechanism if the module wasn't named.
+ git-config submodule."$path".url "$url" ||
+ die "Failed to register url for submodule '$path'"
- module_clone "$path" "$url" || exit
-
- (unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
- die "Checkout of submodule '$path' failed"
-
- say "Submodule '$path' initialized"
+ say "Submodule '$path' registered with url '$url'"
done
}
#
-# Checkout correct revision of each initialized submodule
+# Update each submodule path to correct revision, using clone and checkout as needed
#
# $@ = requested paths (default to all)
#
@@ -101,14 +87,21 @@ modules_update()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
- if ! test -d "$path"/.git
+ url=$(git-config submodule."$path".url)
+ if test -z "$url"
then
# Only mention uninitialized submodules when its
# path have been specified
test "$#" != "0" &&
say "Submodule '$path' not initialized"
- continue;
+ continue
fi
+
+ if ! test -d "$path"/.git
+ then
+ module_clone "$path" "$url" || exit
+ fi
+
subsha1=$(unset GIT_DIR && cd "$path" &&
git-rev-parse --verify HEAD) ||
die "Unable to find current revision of submodule '$path'"
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 6274729..3940433 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 ./.subrepo
+ GIT_CONFIG=.gitmodules git-config module.lib.url git://example.com/lib.git
'
test_expect_success 'status should only print one line' '
@@ -52,41 +52,55 @@ test_expect_success 'status should initially be "missing"' '
git-submodule status | grep "^-$rev1"
'
-test_expect_success 'init should fail when path is used by a file' '
+test_expect_success 'init should register submodule url in .git/config' '
+ git-submodule init &&
+ url=$(git-config submodule.lib.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
+ then
+ echo "[OOPS] init succeeded but update of url failed"
+ false
+ fi
+'
+
+test_expect_success 'update should fail when path is used by a file' '
echo "hello" >lib &&
- if git-submodule init
+ if git-submodule update
then
- echo "[OOPS] init should have failed"
+ echo "[OOPS] update should have failed"
false
elif test -f lib && test "$(cat lib)" != "hello"
then
- echo "[OOPS] init failed but lib file was molested"
+ echo "[OOPS] update failed but lib file was molested"
false
else
rm lib
fi
'
-test_expect_success 'init should fail when path is used by a nonempty directory' '
+test_expect_success 'update should fail when path is used by a nonempty directory' '
mkdir lib &&
echo "hello" >lib/a &&
- if git-submodule init
+ if git-submodule update
then
- echo "[OOPS] init should have failed"
+ echo "[OOPS] update should have failed"
false
elif test "$(cat lib/a)" != "hello"
then
- echo "[OOPS] init failed but lib/a was molested"
+ echo "[OOPS] update failed but lib/a was molested"
false
else
rm lib/a
fi
'
-test_expect_success 'init should work when path is an empty dir' '
+test_expect_success 'update should work when path is an empty dir' '
rm -rf lib &&
mkdir lib &&
- git-submodule init &&
+ git-submodule update &&
head=$(cd lib && git-rev-parse HEAD) &&
if test -z "$head"
then
@@ -99,7 +113,7 @@ test_expect_success 'init should work when path is an empty dir' '
fi
'
-test_expect_success 'status should be "up-to-date" after init' '
+test_expect_success 'status should be "up-to-date" after update' '
git-submodule status | grep "^ $rev1"
'
--
1.5.2.841.gc9eafb
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] git-submodule: move cloning into a separate function
2007-06-05 11:13 ` Lars Hjemli
@ 2007-06-06 8:55 ` Junio C Hamano
2007-06-17 14:38 ` Sven Verdoolaege
1 sibling, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2007-06-06 8:55 UTC (permalink / raw)
To: Lars Hjemli; +Cc: Johannes Sixt, git@vger.kernel.org
"Lars Hjemli" <hjemli@gmail.com> writes:
> This is just a simple refactoring of modules_init() with no change in
> functionality.
>
> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
> ---
>
> On Tue, 05 Jun 2007 12:40:50 +0200, Johannes Sixt <J.Sixt@eudaptics.com> wrote:
>
>> Lars Hjemli wrote:
>>> + module_clone "$path" "$url" || exit $?
>>
>> Minor nit: The idiom that is commonly used in situations like this (see
>> other git-* shell scripts):
>>
>> module_clone "$path" "$url" || exit
>>
>> because exit without argument uses the code of the last command
>> executed.
>>
>
> Thanks, I'll follow up with matching changes to [patch 2/2].
>
This seems to be WS munged by your mailer.
> ...
> + die "Clone of submodule '$path' failed"
> +}
> +
> #
> # Run clone + checkout on missing submodules
> #
> @@ -40,20 +67,6 @@ modules_init()
> # repository
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/2] git-submodule: move cloning into a separate function
[not found] ` <863f2ca67857bc2d09f46f1a5ef6f653d16d5256.1181034736.git.hjemli@gmail.com>
2007-06-05 9:29 ` [PATCH 1/2] git-submodule: move cloning into a separate function Lars Hjemli
[not found] ` <c14730acf8a52a57250303c033ebec09bf960007.1181034736.git.hjemli@gmail.com>
@ 2007-06-06 9:13 ` Lars Hjemli
2 siblings, 0 replies; 11+ messages in thread
From: Lars Hjemli @ 2007-06-06 9:13 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Sixt, git
This is just a simple refactoring of modules_init() with no change in
functionality.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
On 6/6/07, Junio C Hamano <junkio@cox.net> wrote:
> This seems to be WS munged by your mailer.
Ouch, I didn't notice...
git-submodule.sh | 44 ++++++++++++++++++++++++++++----------------
1 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 6ed5a6c..a89ea88 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -25,6 +25,33 @@ say()
fi
}
+
+#
+# Clone a submodule
+#
+module_clone()
+{
+ path=$1
+ url=$2
+
+ # If there already is a directory at the submodule path,
+ # expect it to be empty (since that is the default checkout
+ # action) and try to remove it.
+ # Note: if $path is a symlink to a directory the test will
+ # succeed but the rmdir will fail. We might want to fix this.
+ if test -d "$path"
+ then
+ rmdir "$path" 2>/dev/null ||
+ die "Directory '$path' exist, but is neither empty nor a git repository"
+ fi
+
+ test -e "$path" &&
+ die "A file already exist at path '$path'"
+
+ git-clone -n "$url" "$path" ||
+ die "Clone of submodule '$path' failed"
+}
+
#
# Run clone + checkout on missing submodules
#
@@ -40,20 +67,6 @@ modules_init()
# repository
test -d "$path"/.git && continue
- # If there already is a directory at the submodule path,
- # expect it to be empty (since that is the default checkout
- # action) and try to remove it.
- # Note: if $path is a symlink to a directory the test will
- # succeed but the rmdir will fail. We might want to fix this.
- if test -d "$path"
- then
- rmdir "$path" 2>/dev/null ||
- die "Directory '$path' exist, but is neither empty nor a git repository"
- fi
-
- test -e "$path" &&
- die "A file already exist at path '$path'"
-
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
test -z "$url" &&
die "No url found for submodule '$path' in .gitmodules"
@@ -69,8 +82,7 @@ modules_init()
# logical modulename (if present) as key. But this would need
# another fallback mechanism if the module wasn't named.
- git-clone -n "$url" "$path" ||
- die "Clone of submodule '$path' failed"
+ module_clone "$path" "$url" || exit
(unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
die "Checkout of submodule '$path' failed"
--
1.5.2.841.gc9eafb
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] git-submodule: clone during update, not during init
[not found] ` <c14730acf8a52a57250303c033ebec09bf960007.1181034736.git.hjemli@gmail.com>
2007-06-05 9:29 ` [PATCH 2/2] git-submodule: clone during update, not during init Lars Hjemli
@ 2007-06-06 9:13 ` Lars Hjemli
1 sibling, 0 replies; 11+ messages in thread
From: Lars Hjemli @ 2007-06-06 9:13 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Sixt, git
This teaches 'git-submodule init' to register submodule paths and urls in
.git/config instead of actually cloning them. The cloning is now handled
as part of 'git-submodule update'.
With this change it is possible to specify preferred/alternate urls for
the submodules in .git/config before the submodules are cloned.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
Documentation/git-submodule.txt | 16 +++++++-------
git-submodule.sh | 41 ++++++++++++++++----------------------
t/t7400-submodule-basic.sh | 38 ++++++++++++++++++++++++-----------
3 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index cb0424f..f8fb80f 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -23,15 +23,15 @@ status::
repository. This command is the default command for git-submodule.
init::
- Initialize the submodules, i.e. clone the git repositories specified
- in the .gitmodules file and checkout the submodule commits specified
- in the index of the containing repository. This will make the
- submodules HEAD be detached.
+ Initialize the submodules, i.e. register in .git/config each submodule
+ path and url found in .gitmodules. The key used in git/config is
+ `submodule.$path.url`. This command does not alter existing information
+ in .git/config.
update::
- Update the initialized submodules, i.e. checkout the submodule commits
- specified in the index of the containing repository. This will make
- the submodules HEAD be detached.
+ Update the registered submodules, i.e. clone missing submodules and
+ checkout the commit specified in the index of the containing repository.
+ This will make the submodules HEAD be detached.
OPTIONS
@@ -50,7 +50,7 @@ OPTIONS
FILES
-----
-When cloning submodules, a .gitmodules file in the top-level directory
+When initializing submodules, a .gitmodules file in the top-level directory
of the containing repository is used to find the url of each submodule.
This file should be formatted in the same way as $GIR_DIR/config. The key
to each submodule url is "module.$path.url".
diff --git a/git-submodule.sh b/git-submodule.sh
index a89ea88..e7b6978 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -53,7 +53,7 @@ module_clone()
}
#
-# Run clone + checkout on missing submodules
+# Register submodules in .git/config
#
# $@ = requested paths (default to all)
#
@@ -62,37 +62,23 @@ modules_init()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
- # Skip submodule paths that already contain a .git directory.
- # This will also trigger if $path is a symlink to a git
- # repository
- test -d "$path"/.git && continue
+ # Skip already registered paths
+ url=$(git-config submodule."$path".url)
+ test -z "$url" || continue
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
test -z "$url" &&
die "No url found for submodule '$path' in .gitmodules"
- # MAYBE FIXME: this would be the place to check GIT_CONFIG
- # for a preferred url for this submodule, possibly like this:
- #
- # modname=$(GIT_CONFIG=.gitmodules git-config module."$path".name)
- # alturl=$(git-config module."$modname".url)
- #
- # This would let the versioned .gitmodules file use the submodule
- # path as key, while the unversioned GIT_CONFIG would use the
- # logical modulename (if present) as key. But this would need
- # another fallback mechanism if the module wasn't named.
+ git-config submodule."$path".url "$url" ||
+ die "Failed to register url for submodule '$path'"
- module_clone "$path" "$url" || exit
-
- (unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
- die "Checkout of submodule '$path' failed"
-
- say "Submodule '$path' initialized"
+ say "Submodule '$path' registered with url '$url'"
done
}
#
-# Checkout correct revision of each initialized submodule
+# Update each submodule path to correct revision, using clone and checkout as needed
#
# $@ = requested paths (default to all)
#
@@ -101,14 +87,21 @@ modules_update()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
- if ! test -d "$path"/.git
+ url=$(git-config submodule."$path".url)
+ if test -z "$url"
then
# Only mention uninitialized submodules when its
# path have been specified
test "$#" != "0" &&
say "Submodule '$path' not initialized"
- continue;
+ continue
fi
+
+ if ! test -d "$path"/.git
+ then
+ module_clone "$path" "$url" || exit
+ fi
+
subsha1=$(unset GIT_DIR && cd "$path" &&
git-rev-parse --verify HEAD) ||
die "Unable to find current revision of submodule '$path'"
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 6274729..3940433 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 ./.subrepo
+ GIT_CONFIG=.gitmodules git-config module.lib.url git://example.com/lib.git
'
test_expect_success 'status should only print one line' '
@@ -52,41 +52,55 @@ test_expect_success 'status should initially be "missing"' '
git-submodule status | grep "^-$rev1"
'
-test_expect_success 'init should fail when path is used by a file' '
+test_expect_success 'init should register submodule url in .git/config' '
+ git-submodule init &&
+ url=$(git-config submodule.lib.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
+ then
+ echo "[OOPS] init succeeded but update of url failed"
+ false
+ fi
+'
+
+test_expect_success 'update should fail when path is used by a file' '
echo "hello" >lib &&
- if git-submodule init
+ if git-submodule update
then
- echo "[OOPS] init should have failed"
+ echo "[OOPS] update should have failed"
false
elif test -f lib && test "$(cat lib)" != "hello"
then
- echo "[OOPS] init failed but lib file was molested"
+ echo "[OOPS] update failed but lib file was molested"
false
else
rm lib
fi
'
-test_expect_success 'init should fail when path is used by a nonempty directory' '
+test_expect_success 'update should fail when path is used by a nonempty directory' '
mkdir lib &&
echo "hello" >lib/a &&
- if git-submodule init
+ if git-submodule update
then
- echo "[OOPS] init should have failed"
+ echo "[OOPS] update should have failed"
false
elif test "$(cat lib/a)" != "hello"
then
- echo "[OOPS] init failed but lib/a was molested"
+ echo "[OOPS] update failed but lib/a was molested"
false
else
rm lib/a
fi
'
-test_expect_success 'init should work when path is an empty dir' '
+test_expect_success 'update should work when path is an empty dir' '
rm -rf lib &&
mkdir lib &&
- git-submodule init &&
+ git-submodule update &&
head=$(cd lib && git-rev-parse HEAD) &&
if test -z "$head"
then
@@ -99,7 +113,7 @@ test_expect_success 'init should work when path is an empty dir' '
fi
'
-test_expect_success 'status should be "up-to-date" after init' '
+test_expect_success 'status should be "up-to-date" after update' '
git-submodule status | grep "^ $rev1"
'
--
1.5.2.841.gc9eafb
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] git-submodule: move cloning into a separate function
2007-06-05 11:13 ` Lars Hjemli
2007-06-06 8:55 ` Junio C Hamano
@ 2007-06-17 14:38 ` Sven Verdoolaege
2007-06-17 15:56 ` Lars Hjemli
1 sibling, 1 reply; 11+ messages in thread
From: Sven Verdoolaege @ 2007-06-17 14:38 UTC (permalink / raw)
To: Lars Hjemli; +Cc: Johannes Sixt, git@vger.kernel.org
On Tue, Jun 05, 2007 at 01:13:28PM +0200, Lars Hjemli wrote:
> +module_clone()
> +{
> + path=$1
> + url=$2
> +
> + # If there already is a directory at the submodule path,
> + # expect it to be empty (since that is the default checkout
> + # action) and try to remove it.
> + # Note: if $path is a symlink to a directory the test will
> + # succeed but the rmdir will fail. We might want to fix this.
> + if test -d "$path"
> + then
> + rmdir "$path" 2>/dev/null ||
> + die "Directory '$path' exist, but is neither empty nor a git repository"
What makes you say that '$path' is not a git repository?
skimo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] git-submodule: move cloning into a separate function
2007-06-17 14:38 ` Sven Verdoolaege
@ 2007-06-17 15:56 ` Lars Hjemli
0 siblings, 0 replies; 11+ messages in thread
From: Lars Hjemli @ 2007-06-17 15:56 UTC (permalink / raw)
To: skimo; +Cc: Johannes Sixt, git@vger.kernel.org
On 6/17/07, Sven Verdoolaege <skimo@kotnet.org> wrote:
> On Tue, Jun 05, 2007 at 01:13:28PM +0200, Lars Hjemli wrote:
> > +module_clone()
> > +{
> > + path=$1
> > + url=$2
> > +
> > + # If there already is a directory at the submodule path,
> > + # expect it to be empty (since that is the default checkout
> > + # action) and try to remove it.
> > + # Note: if $path is a symlink to a directory the test will
> > + # succeed but the rmdir will fail. We might want to fix this.
> > + if test -d "$path"
> > + then
> > + rmdir "$path" 2>/dev/null ||
> > + die "Directory '$path' exist, but is neither empty nor a git repository"
>
> What makes you say that '$path' is not a git repository?
>
The function assumes it's only invoked when no repo is present in $path/.git.
--
larsh
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-06-17 15:56 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-05 9:29 [PATCH 0/2] git-submodule: make it easier to use alternate urls Lars Hjemli
[not found] ` <863f2ca67857bc2d09f46f1a5ef6f653d16d5256.1181034736.git.hjemli@gmail.com>
2007-06-05 9:29 ` [PATCH 1/2] git-submodule: move cloning into a separate function Lars Hjemli
2007-06-05 10:40 ` Johannes Sixt
2007-06-05 11:13 ` Lars Hjemli
2007-06-06 8:55 ` Junio C Hamano
2007-06-17 14:38 ` Sven Verdoolaege
2007-06-17 15:56 ` Lars Hjemli
[not found] ` <c14730acf8a52a57250303c033ebec09bf960007.1181034736.git.hjemli@gmail.com>
2007-06-05 9:29 ` [PATCH 2/2] git-submodule: clone during update, not during init Lars Hjemli
2007-06-05 11:18 ` Lars Hjemli
2007-06-06 9:13 ` Lars Hjemli
2007-06-06 9:13 ` [PATCH 1/2] git-submodule: move cloning into a separate function 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).