blame: prevent error if range ends past end of file
[gitweb.git] / builtin / submodule--helper.c
index b1daca995f2f46ceb15148b609c4a89ccaa13de4..4f35c98bb970328bca5135bd66fdaf3a9fce0d16 100644 (file)
@@ -1019,7 +1019,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix)
 
        struct option module_deinit_options[] = {
                OPT__QUIET(&quiet, N_("Suppress submodule status output")),
-               OPT__FORCE(&force, N_("Remove submodule working trees even if they contain local changes")),
+               OPT__FORCE(&force, N_("Remove submodule working trees even if they contain local changes"), 0),
                OPT_BOOL(0, "all", &all, N_("Unregister all submodules")),
                OPT_END()
        };
@@ -1042,7 +1042,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix)
                die(_("Use '--all' if you really want to deinitialize all submodules"));
 
        if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0)
-               BUG("module_list_compute should not choke on empty pathspec");
+               return 1;
 
        info.prefix = prefix;
        if (quiet)
@@ -1817,6 +1817,29 @@ static int is_active(int argc, const char **argv, const char *prefix)
        return !is_submodule_active(the_repository, argv[1]);
 }
 
+/*
+ * Exit non-zero if any of the submodule names given on the command line is
+ * invalid. If no names are given, filter stdin to print only valid names
+ * (which is primarily intended for testing).
+ */
+static int check_name(int argc, const char **argv, const char *prefix)
+{
+       if (argc > 1) {
+               while (*++argv) {
+                       if (check_submodule_name(*argv) < 0)
+                               return 1;
+               }
+       } else {
+               struct strbuf buf = STRBUF_INIT;
+               while (strbuf_getline(&buf, stdin) != EOF) {
+                       if (!check_submodule_name(buf.buf))
+                               printf("%s\n", buf.buf);
+               }
+               strbuf_release(&buf);
+       }
+       return 0;
+}
+
 #define SUPPORT_SUPER_PREFIX (1<<0)
 
 struct cmd_struct {
@@ -1842,6 +1865,7 @@ static struct cmd_struct commands[] = {
        {"push-check", push_check, 0},
        {"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
        {"is-active", is_active, 0},
+       {"check-name", check_name, 0},
 };
 
 int cmd_submodule__helper(int argc, const char **argv, const char *prefix)