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

[PATCH 2/2] submodule.c: warn about missing submodule commit in recursive actions

From
Stefan Beller <sbeller@google.com>
Date
Sep 5, 2018, 23:19 UTC
Message-ID
<20180905231952.28145-2-sbeller@google.com>
In-Reply-To
<20180905231952.28145-1-sbeller@google.com>
By checking if a submodule commit exists before attempting the update
we can improve the error message from the
    error(_("Submodule '%s' could not be updated."), path);
to the new and more specific
    error(_("Submodule '%s' doesn't have commit '%s'"),
          path, oid_to_hex(new_oid));
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/submodule.c b/submodule.c
index da2ed8696f5..56104af1c7c 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1605,6 +1605,7 @@ int submodule_move_head(const char *path,
 	struct child_process cp = CHILD_PROCESS_INIT;
 	const struct submodule *sub;
 	int *error_code_ptr, error_code;
+	struct repository subrepo;
 
 	if (!is_submodule_active(the_repository, path))
 		return 0;
@@ -1627,6 +1628,13 @@ int submodule_move_head(const char *path,
 	if (!sub)
 		BUG("could not get submodule information for '%s'", path);
 
+	if (repo_submodule_init(&subrepo, the_repository, path) < 0)
+		warning(_("Could not get submodule repository for submodule 's'"), path);
+	else if (new_oid && !lookup_commit(subrepo, new_oid)) {
+		return error(_("Submodule '%s' doesn't have commit '%s'"),
+			     path, oid_to_hex(new_oid));
+	}
+
 	if (old_head && !(flags & SUBMODULE_MOVE_HEAD_FORCE)) {
 		/* Check if the submodule has a dirty index. */
 		if (submodule_has_dirty_index(sub))
-- 
2.19.0.rc2.392.g5ba43deb5a-goog
Previous: Stefan BellerNext: Jonathan Nieder
Message 2 of 6 in “submodule.c: convert submodule_move_head new argument to object id”
  1. 1/2 submodule.c: convert submodule_move_head new argument to object idStefan Beller, Sep 5, 2018
  2. 2/2 submodule.c: warn about missing submodule commit in recursive actionsStefan Beller, Sep 5, 2018
  3. Jonathan NiederSep 5, 2018
  4. Martin ÅgrenSep 6, 2018
  5. Jonathan NiederSep 5, 2018
  6. Junio C HamanoSep 6, 2018

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.