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 <[email protected]>
---
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