git submodule add: make the <path> parameter optional
When <path> is not given, use the "humanish" part of the source repository instead. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jens Lehmann committed
Sep 22, 2009 at 17:10 UTC
1414e5788b85787a712a30977b388200f1bc04da
3 files changed
+28
-3
Documentation/git-submodule.txt
+6
-2
@@ -10,7 +10,7 @@ SYNOPSIS
10
--------
11
[verse]
12
'git submodule' [--quiet] add [-b branch]
13
- [--reference <repository>] [--] <repository> <path>
13
+ [--reference <repository>] [--] <repository> [<path>]
14
'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
15
'git submodule' [--quiet] init [--] [<path>...]
16
'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]
@@ -69,7 +69,11 @@ add::
69
to the changeset to be committed next to the current
70
project: the current project is termed the "superproject".
71
+
72
-This requires two arguments: <repository> and <path>.
72
+This requires at least one argument: <repository>. The optional
73
+argument <path> is the relative location for the cloned submodule
74
+to exist in the superproject. If <path> is not given, the
75
+"humanish" part of the source repository is used ("repo" for
76
+"/path/to/repo.git" and "foo" for "host.xz:foo/.git").
77
+
78
<repository> is the URL of the new submodule's origin repository.
79
This may be either an absolute URL, or (if it begins with ./
git-submodule.sh
+6
-1
@@ -5,7 +5,7 @@
5
# Copyright (c) 2007 Lars Hjemli
6
7
dashless=$(basename "$0" | sed -e 's/-/ /')
8
-USAGE="[--quiet] add [-b branch] [--reference <repository>] [--] <repository> <path>
8
+USAGE="[--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
9
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
10
or: $dashless [--quiet] init [--] [<path>...]
11
or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
@@ -160,6 +160,11 @@ cmd_add()
160
repo=$1
161
path=$2
162
163
+ if test -z "$path"; then
164
+ path=$(echo "$repo" |
165
+ sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
166
+ fi
167
+
168
if test -z "$repo" -o -z "$path"; then
169
usage
170
fi
t/t7400-submodule-basic.sh
+16
@@ -306,4 +306,20 @@ test_expect_success 'submodule <invalid-path> warns' '
306
307
'
308
309
+test_expect_success 'add submodules without specifying an explicit path' '
310
+ mkdir repo &&
311
+ cd repo &&
312
+ git init &&
313
+ echo r >r &&
314
+ git add r &&
315
+ git commit -m "repo commit 1" &&
316
+ cd .. &&
317
+ git clone --bare repo/ bare.git &&
318
+ cd addtest &&
319
+ git submodule add "$submodurl/repo" &&
320
+ git config -f .gitmodules submodule.repo.path repo &&
321
+ git submodule add "$submodurl/bare.git" &&
322
+ git config -f .gitmodules submodule.bare.path bare
323
+'
324
+
325
test_done