Skip to content

Commit 6a09ff1

Browse files
committed
Merge branch 'jl/submodule-add-noname'
* jl/submodule-add-noname: git submodule add: make the <path> parameter optional
2 parents 3fa95ce + 1414e57 commit 6a09ff1

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Documentation/git-submodule.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git submodule' [--quiet] add [-b branch]
13-
[--reference <repository>] [--] <repository> <path>
13+
[--reference <repository>] [--] <repository> [<path>]
1414
'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
1515
'git submodule' [--quiet] init [--] [<path>...]
1616
'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]
@@ -69,7 +69,11 @@ add::
6969
to the changeset to be committed next to the current
7070
project: the current project is termed the "superproject".
7171
+
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").
7377
+
7478
<repository> is the URL of the new submodule's origin repository.
7579
This may be either an absolute URL, or (if it begins with ./

git-submodule.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Copyright (c) 2007 Lars Hjemli
66

77
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>]
99
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
1010
or: $dashless [--quiet] init [--] [<path>...]
1111
or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
@@ -160,6 +160,11 @@ cmd_add()
160160
repo=$1
161161
path=$2
162162

163+
if test -z "$path"; then
164+
path=$(echo "$repo" |
165+
sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
166+
fi
167+
163168
if test -z "$repo" -o -z "$path"; then
164169
usage
165170
fi

t/t7400-submodule-basic.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,20 @@ test_expect_success 'submodule <invalid-path> warns' '
306306
307307
'
308308

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+
309325
test_done

0 commit comments

Comments
 (0)