Skip to content

Commit

Permalink
Merge branch 'jl/submodule-add-relurl-wo-upstream' into maint
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed Aug 16, 2011
2 parents 2a76497 + f22a17e commit f4af7f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion Documentation/git-submodule.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=/
Expand Down Expand Up @@ -238,14 +238,6 @@ 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
else

module_clone "$path" "$realrepo" "$reference" || exit
Expand All @@ -259,7 +251,7 @@ cmd_add()
esac
) || die "Unable to checkout submodule '$path'"
fi
git config submodule."$path".url "$url"
git config submodule."$path".url "$realrepo"

git add $force "$path" ||
die "Failed to add submodule '$path'"
Expand Down
10 changes: 10 additions & 0 deletions t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,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 &&
(
Expand Down

0 comments on commit f4af7f1

Please sign in to comment.