From 8537f0ef936781d3984491603cd1c8ff15d7a8a5 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Mon, 6 Jun 2011 21:57:01 +0200 Subject: submodule add: test failure when url is not configured in superproject This documents the current behavior (submodule add with the url set in the superproject is already tested in t7403, t7406, t7407 and t7506). Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 874279e..cae5fd0 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -446,6 +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' ' + ( + cd addtest && + test_must_fail git submodule add ../repo relative + ) +' + test_expect_success 'set up for relative path tests' ' mkdir reltest && ( -- cgit v0.10.2-6-g49f6 From 4d689320049e1ff3bd31e0468d6f17eeb0b7029c Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Mon, 6 Jun 2011 21:58:04 +0200 Subject: 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 Signed-off-by: Junio C Hamano diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index 1a16ff6..f72e900 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -78,7 +78,9 @@ to exist in the superproject. If is not given, the 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. + is the relative location for the cloned submodule to exist in the superproject. If does not exist, then the diff --git a/git-submodule.sh b/git-submodule.sh index 4361ae4..0c984a8 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" ) ' -- cgit v0.10.2-6-g49f6 From f22a17e8da25a043950a13f11035930922bb86e7 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Mon, 6 Jun 2011 21:58:43 +0200 Subject: submodule add: clean up duplicated code In cmd_add() the switch statement used to resolve a relative url was present twice. Remove the second one and use the realrepo variable set by the first one (lines 194 ff.) instead. Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano diff --git a/git-submodule.sh b/git-submodule.sh index 0c984a8..32cb054 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -238,15 +238,7 @@ cmd_add() die "'$path' already exists and is not a valid git repo" fi - case "$repo" in - ./*|../*) - url=$(resolve_relative_url "$repo") || exit - ;; - *) - url="$repo" - ;; - esac - git config submodule."$path".url "$url" + git config submodule."$path".url "$realrepo" else module_clone "$path" "$realrepo" "$reference" || exit -- cgit v0.10.2-6-g49f6