Merge branch 'jl/submodule-add-relurl-wo-upstream'

* 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
This commit is contained in:
Junio C Hamano 2011-07-22 14:24:35 -07:00
commit c56dce3b81
3 changed files with 15 additions and 11 deletions

View File

@ -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. <repository> is the URL of the new submodule's origin repository.
This may be either an absolute URL, or (if it begins with ./ This may be either an absolute URL, or (if it begins with ./
or ../), the location relative to the superproject's origin 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 <path> is the relative location for the cloned submodule to
exist in the superproject. If <path> does not exist, then the exist in the superproject. If <path> does not exist, then the

View File

@ -35,7 +35,7 @@ resolve_relative_url ()
{ {
remote=$(get_default_remote) remote=$(get_default_remote)
remoteurl=$(git config "remote.$remote.url") || 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" url="$1"
remoteurl=${remoteurl%/} remoteurl=${remoteurl%/}
sep=/ sep=/
@ -242,14 +242,6 @@ Use -f if you really want to add it." &&
die "$(eval_gettext "'\$path' already exists and is not a valid git repo")" die "$(eval_gettext "'\$path' already exists and is not a valid git repo")"
fi fi
case "$repo" in
./*|../*)
url=$(resolve_relative_url "$repo") || exit
;;
*)
url="$repo"
;;
esac
else else
module_clone "$path" "$realrepo" "$reference" || exit module_clone "$path" "$realrepo" "$reference" || exit
@ -263,7 +255,7 @@ Use -f if you really want to add it." &&
esac esac
) || die "$(eval_gettext "Unable to checkout submodule '\$path'")" ) || die "$(eval_gettext "Unable to checkout submodule '\$path'")"
fi fi
git config submodule."$path".url "$url" git config submodule."$path".url "$realrepo"
git add $force "$path" || git add $force "$path" ||
die "$(eval_gettext "Failed to add submodule '\$path'")" die "$(eval_gettext "Failed to add submodule '\$path'")"

View File

@ -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' ' test_expect_success 'set up for relative path tests' '
mkdir reltest && mkdir reltest &&
( (