submodule add: allow relative repository path even when no url is set
Adding a submodule with a relative repository path did only succeed when the superproject's default remote was set. But when that is unset, the superproject is its own authoritative upstream, so lets use its working directory as upstream instead. This allows users to set up a new superpoject where the submodules urls are configured relative to the superproject's upstream while its default remote can be configured later. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jens Lehmann committed
Jun 6, 2011 at 21:58 UTC
4d689320049e1ff3bd31e0468d6f17eeb0b7029c
3 files changed
+9
-4
Documentation/git-submodule.txt
+3
-1
@@ -78,7 +78,9 @@ to exist in the superproject. If <path> is not given, the
78
<repository> is the URL of the new submodule's origin repository.
79
This may be either an absolute URL, or (if it begins with ./
80
or ../), the location relative to the superproject's origin
81
-repository.
81
+repository. If the superproject doesn't have an origin configured
82
+the superproject is its own authoritative upstream and the current
83
+working directory is used instead.
84
+
85
<path> is the relative location for the cloned submodule to
86
exist in the superproject. If <path> does not exist, then the
git-submodule.sh
+1
-1
@@ -34,7 +34,7 @@ resolve_relative_url ()
34
{
35
remote=$(get_default_remote)
36
remoteurl=$(git config "remote.$remote.url") ||
37
- die "remote ($remote) does not have a url defined in .git/config"
37
+ remoteurl=$(pwd) # the repository is its own authoritative upstream
38
url="$1"
39
remoteurl=${remoteurl%/}
40
sep=/
t/t7400-submodule-basic.sh
+5
-2
@@ -446,10 +446,13 @@ test_expect_success 'add should fail when path is used by an existing directory'
446
)
447
'
448
449
-test_expect_success 'add should fail when path is relative but no url is set in the superproject' '
449
+test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
450
(
451
cd addtest &&
452
- test_must_fail git submodule add ../repo relative
452
+ git submodule add ../repo relative &&
453
+ test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
454
+ git submodule sync relative &&
455
+ test "$(git config submodule.relative.url)" = "$submodurl/repo"
456
)
457
'
458