author | Junio C Hamano <gitster@pobox.com> | |
Fri, 22 Jul 2011 21:24:35 +0000 (14:24 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 22 Jul 2011 21:24:35 +0000 (14:24 -0700) |
* jl/submodule-add-relurl-wo-upstream:
submodule add: clean up duplicated code
submodule add: allow relative repository path even when no url is set
submodule add: test failure when url is not configured in superproject
Conflicts:
git-submodule.sh
submodule add: clean up duplicated code
submodule add: allow relative repository path even when no url is set
submodule add: test failure when url is not configured in superproject
Conflicts:
git-submodule.sh
Documentation/git-submodule.txt | patch | blob | history | |
git-submodule.sh | patch | blob | history | |
t/t7400-submodule-basic.sh | patch | blob | history |
index acb9002fe432c6849bd894567d2272bfbe8efdbc..0ec85742ddc1c360d066659fb562898a259e48f7 100644 (file)
<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 3daa0c834cad1ed402376adf535c73e1c06172e4..bc1d3fa663a5eb39dd96f6ad2ca17437073ceb0a 100755 (executable)
--- a/git-submodule.sh
+++ b/git-submodule.sh
{
remote=$(get_default_remote)
remoteurl=$(git config "remote.$remote.url") ||
- die "$(eval_gettext "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=/
die "$(eval_gettext "'\$path' already exists and is not a valid git repo")"
fi
- case "$repo" in
- ./*|../*)
- url=$(resolve_relative_url "$repo") || exit
- ;;
- *)
- url="$repo"
- ;;
- esac
else
module_clone "$path" "$realrepo" "$reference" || exit
esac
) || die "$(eval_gettext "Unable to checkout submodule '\$path'")"
fi
- git config submodule."$path".url "$url"
+ git config submodule."$path".url "$realrepo"
git add $force "$path" ||
die "$(eval_gettext "Failed to add submodule '\$path'")"
index b2b26b72d05a392d8adb83be50c1bb9e73c4eb2d..5afe6ccd78f7171c6bdbb5be35d9663a618c1c73 100755 (executable)
@@ -446,6 +446,16 @@ test_expect_success 'add should fail when path is used by an existing directory'
)
'
+test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
+ (
+ cd addtest &&
+ 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"
+ )
+'
+
test_expect_success 'set up for relative path tests' '
mkdir reltest &&
(