Skip to content

Commit f4af7f1

Browse files
committed
Merge branch 'jl/submodule-add-relurl-wo-upstream' into maint
* 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
2 parents 2a76497 + f22a17e commit f4af7f1

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

Documentation/git-submodule.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ to exist in the superproject. If <path> is not given, the
7878
<repository> is the URL of the new submodule's origin repository.
7979
This may be either an absolute URL, or (if it begins with ./
8080
or ../), the location relative to the superproject's origin
81-
repository.
81+
repository. If the superproject doesn't have an origin configured
82+
the superproject is its own authoritative upstream and the current
83+
working directory is used instead.
8284
+
8385
<path> is the relative location for the cloned submodule to
8486
exist in the superproject. If <path> does not exist, then the

git-submodule.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resolve_relative_url ()
3434
{
3535
remote=$(get_default_remote)
3636
remoteurl=$(git config "remote.$remote.url") ||
37-
die "remote ($remote) does not have a url defined in .git/config"
37+
remoteurl=$(pwd) # the repository is its own authoritative upstream
3838
url="$1"
3939
remoteurl=${remoteurl%/}
4040
sep=/
@@ -238,14 +238,6 @@ cmd_add()
238238
die "'$path' already exists and is not a valid git repo"
239239
fi
240240

241-
case "$repo" in
242-
./*|../*)
243-
url=$(resolve_relative_url "$repo") || exit
244-
;;
245-
*)
246-
url="$repo"
247-
;;
248-
esac
249241
else
250242

251243
module_clone "$path" "$realrepo" "$reference" || exit
@@ -259,7 +251,7 @@ cmd_add()
259251
esac
260252
) || die "Unable to checkout submodule '$path'"
261253
fi
262-
git config submodule."$path".url "$url"
254+
git config submodule."$path".url "$realrepo"
263255

264256
git add $force "$path" ||
265257
die "Failed to add submodule '$path'"

t/t7400-submodule-basic.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,16 @@ test_expect_success 'add should fail when path is used by an existing directory'
448448
)
449449
'
450450

451+
test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
452+
(
453+
cd addtest &&
454+
git submodule add ../repo relative &&
455+
test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
456+
git submodule sync relative &&
457+
test "$(git config submodule.relative.url)" = "$submodurl/repo"
458+
)
459+
'
460+
451461
test_expect_success 'set up for relative path tests' '
452462
mkdir reltest &&
453463
(

0 commit comments

Comments
 (0)