git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] submodule helper: accept '.' for repositories with no submodules
@ 2016-03-22 17:59 Stefan Beller
  2016-03-22 18:53 ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Beller @ 2016-03-22 17:59 UTC (permalink / raw)
  To: gitster, cederp; +Cc: Jens.Lehmann, git, Stefan Beller

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-03-22 22:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-22 17:59 [PATCH] submodule helper: accept '.' for repositories with no submodules Stefan Beller
2016-03-22 18:53 ` 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

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).