[PATCH] submodule helper: accept '.' for repositories with no submodules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---

 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]