All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org
Cc: Stefan Beller <sbeller@google.com>
Subject: [PATCH 2/2] submodule.c: warn about missing submodule commit in recursive actions
Date: Wed,  5 Sep 2018 16:19:52 -0700	[thread overview]
Message-ID: <20180905231952.28145-2-sbeller@google.com> (raw)
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


  reply	other threads:[~2018-09-05 23:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-05 23:19 [PATCH 1/2] submodule.c: convert submodule_move_head new argument to object id Stefan Beller
2018-09-05 23:19 ` Stefan Beller [this message]
2018-09-05 23:32   ` [PATCH 2/2] submodule.c: warn about missing submodule commit in recursive actions Jonathan Nieder
2018-09-06  6:22   ` Martin Ågren
2018-09-05 23:40 ` [PATCH 1/2] submodule.c: convert submodule_move_head new argument to object id Jonathan Nieder
2018-09-06 21:18 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180905231952.28145-2-sbeller@google.com \
    --to=sbeller@google.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.