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

[PATCH v3 4/5] submodule--helper: add push-check subcommand

From
BWBrandon Williams <bmwill@google.com>
Date
Apr 5, 2017, 17:47 UTC
Message-ID
<20170405174719.1297-5-bmwill@google.com>
In-Reply-To
<20170405174719.1297-1-bmwill@google.com>

Add the 'push-check' subcommand to submodule--helper which is used to check if the provided remote and refspec can be used as part of a push operation in the submodule.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 builtin/submodule--helper.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 85aafe46a..6ee962207 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1105,6 +1105,50 @@ static int resolve_remote_submodule_branch(int argc, const char **argv,
 	return 0;
 }
 
+static int push_check(int argc, const char **argv, const char *prefix)
+{
+	struct remote *remote;
+
+	if (argc < 2)
+		die("submodule--helper push-check requires at least 1 argument");
+
+	/*
+	 * The remote must be configured.
+	 * This is to avoid pushing to the exact same URL as the parent.
+	 */
+	remote = pushremote_get(argv[1]);
+	if (!remote || remote->origin == REMOTE_UNCONFIGURED)
+		die("remote '%s' not configured", argv[1]);
+
+	/* Check the refspec */
+	if (argc > 2) {
+		int i, refspec_nr = argc - 2;
+		struct ref *local_refs = get_local_heads();
+		struct refspec *refspec = parse_push_refspec(refspec_nr,
+							     argv + 2);
+
+		for (i = 0; i < refspec_nr; i++) {
+			struct refspec *rs = refspec + i;
+
+			if (rs->pattern || rs->matching)
+				continue;
+
+			/*
+			 * LHS must match a single ref
+			 * NEEDSWORK: add logic to special case 'HEAD' once
+			 * working with submodules in a detached head state
+			 * ceases to be the norm.
+			 */
+			if (count_refspec_match(rs->src, local_refs, NULL) != 1)
+				die("src refspec '%s' must name a ref",
+				    rs->src);
+		}
+		free_refspec(refspec_nr, refspec);
+	}
+
+	return 0;
+}
+
 static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
 {
 	int i;
@@ -1170,6 +1214,7 @@ static struct cmd_struct commands[] = {
 	{"resolve-relative-url-test", resolve_relative_url_test, 0},
 	{"init", module_init, SUPPORT_SUPER_PREFIX},
 	{"remote-branch", resolve_remote_submodule_branch, 0},
+	{"push-check", push_check, 0},
 	{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
 	{"is-active", is_active, 0},
 };
-- 
2.12.2.715.g7642488e1d-goog
Previous: Brandon WilliamsNext: Brandon Williams
Message 15 of 19 in “push: propagate push-options with --recurse-submodules”
  1. push: propagate push-options with --recurse-submodulesBrandon Williams, Mar 31, 2017
  2. Jonathan NiederMar 31, 2017
  3. Brandon WilliamsMar 31, 2017
  4. 0/2 propagate push-optionsBrandon Williams, Mar 31, 2017
  5. 1/2 push: unmark a local variable as staticBrandon Williams, Mar 31, 2017
  6. Jonathan NiederApr 1, 2017
  7. Brandon WilliamsApr 1, 2017
  8. 2/2 push: propagate push-options with --recurse-submodulesBrandon Williams, Mar 31, 2017
  9. Jonathan NiederApr 1, 2017
  10. Jacob KellerApr 6, 2017
  11. Brandon WilliamsApr 6, 2017
  12. 0/5 propagating push-options, remote and refspecBrandon Williams, Apr 5, 2017
  13. 2/5 push: propagate push-options with --recurse-submodulesBrandon Williams, Apr 5, 2017
  14. 5/5 push: propagate remote and refspec with --recurse-submodulesBrandon Williams, Apr 5, 2017
  15. 4/5 submodule--helper: add push-check subcommandBrandon Williams, Apr 5, 2017
  16. 1/5 push: unmark a local variable as staticBrandon Williams, Apr 5, 2017
  17. 3/5 remote: expose parse_push_refspec functionBrandon Williams, Apr 5, 2017
  18. Junio C HamanoApr 11, 2017
  19. Brandon WilliamsApr 11, 2017

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.