Thread (8 messages) flat view 8 messages, 3 authors, 2016-06-15
DORMANTno replies

[PATCH 2/3] submodule add: allow relative repository path even when no url is set

From: Jens Lehmann <hidden>
Date: 2016-06-15 22:51:25
Subsystem: documentation, the rest · Maintainers: Jonathan Corbet, Linus Torvalds

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 <redacted>
---
 Documentation/git-submodule.txt |    4 +++-
 git-submodule.sh                |    2 +-
 t/t7400-submodule-basic.sh      |    7 +++++--
 3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 5e7a413..408998e 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -78,7 +78,9 @@ to exist in the superproject. If <path> is not given, the
 <repository> is the URL of the new submodule's origin repository.
 This may be either an absolute URL, or (if it begins with ./
 or ../), the location relative to the superproject's origin
-repository.
+repository. If the superproject doesn't have an origin configured
+the superproject is its own authoritative upstream and the current
+working directory is used instead.
 +
 <path> is the relative location for the cloned submodule to
 exist in the superproject. If <path> does not exist, then the
diff --git a/git-submodule.sh b/git-submodule.sh
index d189a24..3fbc21e 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -34,7 +34,7 @@ resolve_relative_url ()
 {
 	remote=$(get_default_remote)
 	remoteurl=$(git config "remote.$remote.url") ||
-		die "remote ($remote) does not have a url defined in .git/config"
+		remoteurl=$(pwd) # the repository is its own authoritative upstream
 	url="$1"
 	remoteurl=${remoteurl%/}
 	sep=/
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index cae5fd0..9099e80 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -446,10 +446,13 @@ test_expect_success 'add should fail when path is used by an existing directory'
 	)
 '

-test_expect_success 'add should fail when path is relative but no url is set in the superproject' '
+test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
 	(
 		cd addtest &&
-		test_must_fail git submodule add ../repo relative
+		git submodule add ../repo relative &&
+		test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
+		git submodule sync relative &&
+		test "$(git config submodule.relative.url)" = "$submodurl/repo"
 	)
 '
-- 
1.7.6.rc0.3.g28a66
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help