git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/7] submodule--helper: add valid-label-name

From
Stefan Beller <sbeller@google.com>
Date
May 11, 2016, 00:59 UTC
Message-ID
<1462928397-1708-2-git-send-email-sbeller@google.com>
In-Reply-To
<1462928397-1708-1-git-send-email-sbeller@google.com>

We could allow more than just alphanumeric and dash characters for submodule labels. As a precaution we'll first allow only this subset and later on we can extend it once we have more experience with them.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c  | 30 ++++++++++++++++++++++++++-
 t/t7412-submodule--helper.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100755 t/t7412-submodule--helper.sh
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 7f0941d..d3f4684 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -831,6 +831,33 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
+static int submodule_valid_label_name(const char *label)
+{
+	if (!label || !strlen(label))
+		return 0;
+
+	if (!isalnum(*label))
+		return 0;
+
+	while (*label) {
+		if (!(isalnum(*label) ||
+			*label == '-'))
+			return 0;
+		label++;
+	}
+
+	return 1;
+}
+
+static int valid_label_name(int argc, const char **argv, const char *prefix)
+{
+	if (argc == 2 && submodule_valid_label_name(argv[1]))
+		return 0;
+
+	die(_("submodule label must start with an alphanumeric character"
+	      "and must contain alphanumeric characters or dashes only."));
+}
+
 struct cmd_struct {
 	const char *cmd;
 	int (*fn)(int, const char **, const char *);
@@ -843,7 +870,8 @@ static struct cmd_struct commands[] = {
 	{"update-clone", update_clone},
 	{"resolve-relative-url", resolve_relative_url},
 	{"resolve-relative-url-test", resolve_relative_url_test},
-	{"init", module_init}
+	{"init", module_init},
+	{"valid-label-name", valid_label_name}
 };
 
 int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
diff --git a/t/t7412-submodule--helper.sh b/t/t7412-submodule--helper.sh
new file mode 100755
index 0000000..3af315c
--- /dev/null
+++ b/t/t7412-submodule--helper.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+test_description='Basic plumbing support of submodule--helper
+
+This test verifies the submodule--helper plumbing command used to implement
+git-submodule.
+'
+
+. ./test-lib.sh
+
+
+test_expect_success 'valid-label-name tests empty label' '
+	test_must_fail git submodule--helper valid-label-name 2>actual &&
+	test_i18ngrep alphanumeric actual &&
+	test_must_fail git submodule--helper valid-label-name "" 2>actual &&
+	test_i18ngrep alphanumeric actual
+'
+
+test_expect_success 'valid-label-name tests correct label asdf' '
+	git submodule--helper valid-label-name asdf 2>actual &&
+	test_must_be_empty actual
+'
+
+test_expect_success 'valid-label-name tests correct label a' '
+	git submodule--helper valid-label-name a 2>actual &&
+	test_must_be_empty actual
+'
+
+test_expect_success 'valid-label-name tests correct label a-b' '
+	git submodule--helper valid-label-name a-b 2>actual &&
+	test_must_be_empty actual
+'
+
+test_expect_success 'valid-label-name fails with multiple arguments' '
+	test_must_fail git submodule--helper valid-label-name a b 2>actual &&
+	test_i18ngrep alphanumeric actual
+'
+
+test_expect_success 'valid-label-name fails with white spaced arguments' '
+	test_must_fail git submodule--helper valid-label-name "a b" 2>actual &&
+	test_i18ngrep alphanumeric actual
+'
+
+test_expect_success 'valid-label-name fails with utf8 characters' '
+	test_must_fail git submodule--helper valid-label-name ☺ 2>actual &&
+	test_i18ngrep alphanumeric actual
+'
+
+test_done
-- 
2.8.0.35.g58985d9.dirty
Previous: Stefan BellerNext: Junio C Hamano
Message 2 of 30 in “submodule groups”
  1. 0/7 submodule groupsStefan Beller, May 11, 2016
  2. 1/7 submodule--helper: add valid-label-nameStefan Beller, May 11, 2016
  3. Junio C HamanoMay 11, 2016
  4. 2/7 submodule add: label submodules if asked toStefan Beller, May 11, 2016
  5. Junio C HamanoMay 11, 2016
  6. Stefan BellerMay 11, 2016
  7. 3/7 submodule-config: keep labels aroundStefan Beller, May 11, 2016
  8. Junio C HamanoMay 11, 2016
  9. Stefan BellerMay 11, 2016
  10. Junio C HamanoMay 11, 2016
  11. Stefan BellerMay 11, 2016
  12. 4/7 submodule-config: check if a submodule is in a groupStefan Beller, May 11, 2016
  13. Junio C HamanoMay 11, 2016
  14. 5/7 submodule--helper module_list_compute: allow label or name argumentsStefan Beller, May 11, 2016
  15. Junio C HamanoMay 11, 2016
  16. Junio C HamanoMay 11, 2016
  17. 6/7 submodule update: learn partial initializationStefan Beller, May 11, 2016
  18. 7/7 clone: allow specification of submodules to be clonedStefan Beller, May 11, 2016
  19. Junio C HamanoMay 11, 2016
  20. Stefan BellerMay 11, 2016
  21. Junio C HamanoMay 11, 2016
  22. Junio C HamanoMay 11, 2016
  23. Stefan BellerMay 11, 2016
  24. Junio C HamanoMay 12, 2016
  25. Junio C HamanoMay 12, 2016
  26. Junio C HamanoMay 12, 2016
  27. Stefan BellerMay 12, 2016
  28. Junio C HamanoMay 12, 2016
  29. Stefan BellerMay 12, 2016
  30. Junio C HamanoMay 12, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.