From: Stefan Beller <sbeller@google.com>
To: gitster@pobox.com, cederp@opera.com
Cc: Jens.Lehmann@web.de, git@vger.kernel.org,
Stefan Beller <sbeller@google.com>
Subject: [PATCH] submodule helper: accept '.' for repositories with no submodules
Date: Tue, 22 Mar 2016 10:59:39 -0700 [thread overview]
Message-ID: <1458669579-32160-1-git-send-email-sbeller@google.com> (raw)
In 74703a1e4d (2015-09-02, submodule: rewrite `module_list` shell
function in C), "submodule deinit ." was broken.
The original module_list accepted '.' as a pathspec just fine, as it
was using
git ls-files -z --error-unmatch --stage -- "$@" || { custom filtering}
and git ls-files doesn't make a difference between "." and no arguments
there. When using the parse_pathspec function in C, this is a difference
however, when no path matches.
'submodule deinit' asks users to explicitely to give '.' instead of
empty arguments to specify all submodules (as a safety measure?),
so we have to support that as well.
Add a test case to prevent this error coming up again and fix this
by special casing '.' in the new module_list to reduce the difference
between the old and new module_list.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
This applies on v2.7.4
I looked at alternatives of how to fix it, e.g.
later in module_list to make an exception for calling
if (ps_matched && report_path_error(ps_matched, pathspec, prefix))
result = -1;
but that is similarly ugly.
builtin/submodule--helper.c | 8 ++++++++
t/t7400-submodule-basic.sh | 10 ++++++++++
2 files changed, 18 insertions(+)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ed764c9..47e6839 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -23,6 +23,14 @@ static int module_list_compute(int argc, const char **argv,
{
int i, result = 0;
char *ps_matched = NULL;
+
+ /*
+ * We need to treat a path spec of '.' the same as an empty
+ * path spec, because "submodule deinit" wants to be given '.'
+ * instead of an empty list.
+ */
+ if (argc == 1 && !strcmp(".", argv[0]))
+ argv[0] = NULL;
parse_pathspec(pathspec, 0,
PATHSPEC_PREFER_FULL |
PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index be82a75..fdf7105 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -849,6 +849,16 @@ test_expect_success 'set up a second submodule' '
git commit -m "submodule example2 added"
'
+test_expect_success 'submodule deinit -f . works on empty repository' '
+ test_when_finished "rm -rf newdirectory" &&
+ mkdir newdirectory &&
+ (
+ cd newdirectory &&
+ git init &&
+ git submodule deinit .
+ )
+'
+
test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
git config submodule.example.foo bar &&
git config submodule.example2.frotz nitfol &&
--
2.7.4.1.g33fcf9d
next reply other threads:[~2016-03-22 17:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-22 17:59 Stefan Beller [this message]
2016-03-22 18:53 ` [PATCH] submodule helper: accept '.' for repositories with no submodules Junio C Hamano
2016-03-22 19:30 ` Stefan Beller
2016-03-22 20:06 ` Junio C Hamano
2016-03-22 21:16 ` Stefan Beller
2016-03-22 21:38 ` Junio C Hamano
2016-03-22 21:47 ` Stefan Beller
2016-03-22 22:04 ` Junio C Hamano
2016-03-22 22:10 ` Stefan Beller
2016-03-22 22:50 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1458669579-32160-1-git-send-email-sbeller@google.com \
--to=sbeller@google.com \
--cc=Jens.Lehmann@web.de \
--cc=cederp@opera.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).