Skip to content

Commit 4d68932

Browse files
jlehmanngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8537f0e commit 4d68932

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Documentation/git-submodule.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ to exist in the superproject. If <path> is not given, the
7878
<repository> is the URL of the new submodule's origin repository.
7979
This may be either an absolute URL, or (if it begins with ./
8080
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.
8284
+
8385
<path> is the relative location for the cloned submodule to
8486
exist in the superproject. If <path> does not exist, then the

git-submodule.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resolve_relative_url ()
3434
{
3535
remote=$(get_default_remote)
3636
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
3838
url="$1"
3939
remoteurl=${remoteurl%/}
4040
sep=/

t/t7400-submodule-basic.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,13 @@ test_expect_success 'add should fail when path is used by an existing directory'
446446
)
447447
'
448448

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' '
450450
(
451451
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"
453456
)
454457
'
455458

0 commit comments

Comments
 (0)