{"thread":{"id":"20776","subject":"[PATCH] git submodule add: make the <path> parameter optional","startedAt":"2009-08-28T19:19:36Z","lastAt":"2009-08-28T19:19:36Z","messageCount":1,"participants":["Jens Lehmann"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"122042","messageId":"4A982DC8.3000407@web.de","threadId":"20776","inReplyTo":null,"subject":"[PATCH] git submodule add: make the <path> parameter optional","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2009-08-28T19:19:36Z","receivedAt":"2009-08-28T19:19:36Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"When <path> is not given, use the \"humanish\" part of the source repository\ninstead.\n\nSigned-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n---\n\nWith this patch, git submodule add behaves like git clone in this respect.\n\n Documentation/git-submodule.txt |    8 ++++++--\n git-submodule.sh                |    7 ++++++-\n t/t7400-submodule-basic.sh      |   16 ++++++++++++++++\n 3 files changed, 28 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex 5ccdd18..4ef70c4 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git submodule' [--quiet] add [-b branch]\n-\t      [--reference <repository>] [--] <repository> <path>\n+\t      [--reference <repository>] [--] <repository> [<path>]\n 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] init [--] [<path>...]\n 'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]\n@@ -69,7 +69,11 @@ add::\n \tto the changeset to be committed next to the current\n \tproject: the current project is termed the \"superproject\".\n +\n-This requires two arguments: <repository> and <path>.\n+This requires at least one argument: <repository>. The optional\n+argument <path> is the relative location for the cloned submodule\n+to exist in the superproject. If <path> is not given, the\n+\"humanish\" part of the source repository is used (\"repo\" for\n+\"/path/to/repo.git\" and \"foo\" for \"host.xz:foo/.git\").\n +\n <repository> is the URL of the new submodule's origin repository.\n This may be either an absolute URL, or (if it begins with ./\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex bfbd36b..0c617eb 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -5,7 +5,7 @@\n # Copyright (c) 2007 Lars Hjemli\n\n dashless=$(basename \"$0\" | sed -e 's/-/ /')\n-USAGE=\"[--quiet] add [-b branch] [--reference <repository>] [--] <repository> <path>\n+USAGE=\"[--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]\n    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]\n    or: $dashless [--quiet] init [--] [<path>...]\n    or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]\n@@ -160,6 +160,11 @@ cmd_add()\n \trepo=$1\n \tpath=$2\n\n+\tif test -z \"$path\"; then\n+\t\tpath=$(echo \"$repo\" |\n+\t\t\tsed -e 's|/$||' -e 's|:*/*\\.git$||' -e 's|.*[/:]||g')\n+\tfi\n+\n \tif test -z \"$repo\" -o -z \"$path\"; then\n \t\tusage\n \tfi\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 0f2ccc6..a0cc99a 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -306,4 +306,20 @@ test_expect_success 'submodule <invalid-path> warns' '\n\n '\n\n+test_expect_success 'add submodules without specifying an explicit path' '\n+\tmkdir repo &&\n+\tcd repo &&\n+\tgit init &&\n+\techo r >r &&\n+\tgit add r &&\n+\tgit commit -m \"repo commit 1\" &&\n+\tcd .. &&\n+\tgit clone --bare repo/ bare.git &&\n+\tcd addtest &&\n+\tgit submodule add \"$submodurl/repo\" &&\n+\tgit config -f .gitmodules submodule.repo.path repo &&\n+\tgit submodule add \"$submodurl/bare.git\" &&\n+\tgit config -f .gitmodules submodule.bare.path bare\n+'\n+\n test_done\n-- \n1.6.4.1.246.g7bae7.dirty\n"}]}