Skip to content

Commit

Permalink
Merge branch 'js/merge-base-with-missing-commit' into next
Browse files Browse the repository at this point in the history
Make sure failure return from merge_bases_many() is properly caught.

* js/merge-base-with-missing-commit:
  merge-ort/merge-recursive: do report errors in `merge_submodule()`
  merge-recursive: prepare for `merge_submodule()` to report errors
  • Loading branch information
gitster committed Mar 9, 2024
2 parents 2cded1c + 25fd20e commit caa7a7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions merge-ort.c
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,7 @@ static int merge_submodule(struct merge_options *opt,
_("Failed to merge submodule %s "
"(repository corrupt)"),
path);
ret = -1;
goto cleanup;
}
if (ret2 > 0)
Expand All @@ -1831,6 +1832,7 @@ static int merge_submodule(struct merge_options *opt,
_("Failed to merge submodule %s "
"(repository corrupt)"),
path);
ret = -1;
goto cleanup;
}
if (!ret2) {
Expand All @@ -1850,6 +1852,7 @@ static int merge_submodule(struct merge_options *opt,
_("Failed to merge submodule %s "
"(repository corrupt)"),
path);
ret = -1;
goto cleanup;
}
if (ret2 > 0) {
Expand All @@ -1868,6 +1871,7 @@ static int merge_submodule(struct merge_options *opt,
_("Failed to merge submodule %s "
"(repository corrupt)"),
path);
ret = -1;
goto cleanup;
}
if (ret2 > 0) {
Expand Down Expand Up @@ -1901,6 +1905,7 @@ static int merge_submodule(struct merge_options *opt,
_("Failed to merge submodule %s "
"(repository corrupt)"),
path);
ret = -1;
break;
case 0:
path_msg(opt, CONFLICT_SUBMODULE_FAILED_TO_MERGE, 0,
Expand Down
21 changes: 15 additions & 6 deletions merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,12 +1247,14 @@ static int merge_submodule(struct merge_options *opt,
ret2 = repo_in_merge_bases(&subrepo, commit_base, commit_a);
if (ret2 < 0) {
output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
ret = -1;
goto cleanup;
}
if (ret2 > 0)
ret2 = repo_in_merge_bases(&subrepo, commit_base, commit_b);
if (ret2 < 0) {
output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
ret = -1;
goto cleanup;
}
if (!ret2) {
Expand All @@ -1264,6 +1266,7 @@ static int merge_submodule(struct merge_options *opt,
ret2 = repo_in_merge_bases(&subrepo, commit_a, commit_b);
if (ret2 < 0) {
output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
ret = -1;
goto cleanup;
}
if (ret2) {
Expand All @@ -1282,6 +1285,7 @@ static int merge_submodule(struct merge_options *opt,
ret2 = repo_in_merge_bases(&subrepo, commit_b, commit_a);
if (ret2 < 0) {
output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path);
ret = -1;
goto cleanup;
}
if (ret2) {
Expand Down Expand Up @@ -1313,6 +1317,10 @@ static int merge_submodule(struct merge_options *opt,
parent_count = find_first_merges(&subrepo, &merges, path,
commit_a, commit_b);
switch (parent_count) {
case -1:
output(opt, 1,_("Failed to merge submodule %s (repository corrupt)"), path);
ret = -1;
break;
case 0:
output(opt, 1, _("Failed to merge submodule %s (merge following commits not found)"), path);
break;
Expand Down Expand Up @@ -1427,13 +1435,14 @@ static int merge_mode_and_contents(struct merge_options *opt,
/* FIXME: bug, what if modes didn't match? */
result->clean = (merge_status == 0);
} else if (S_ISGITLINK(a->mode)) {
result->clean = merge_submodule(opt, &result->blob.oid,
o->path,
&o->oid,
&a->oid,
&b->oid);
if (result->clean < 0)
int clean = merge_submodule(opt, &result->blob.oid,
o->path,
&o->oid,
&a->oid,
&b->oid);
if (clean < 0)
return -1;
result->clean = clean;
} else if (S_ISLNK(a->mode)) {
switch (opt->recursive_variant) {
case MERGE_VARIANT_NORMAL:
Expand Down

0 comments on commit caa7a7b

Please sign in to comment.