1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-05 19:56:12 +02:00

merge-tree: fail with a non-zero exit code on missing tree objects

When `git merge-tree` encounters a missing tree object, it should error
out and not continue quietly as if nothing had happened.

However, as of time of writing, `git merge-tree` _does_ continue, and
then offers the empty tree as result.

Let's fix this.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin 2024-02-23 08:34:20 +00:00 committed by Junio C Hamano
parent 5f43cf5b2e
commit d4bf19308b
2 changed files with 15 additions and 3 deletions

View File

@ -1659,9 +1659,10 @@ static int collect_merge_info(struct merge_options *opt,
info.data = opt;
info.show_all_errors = 1;
parse_tree(merge_base);
parse_tree(side1);
parse_tree(side2);
if (parse_tree(merge_base) < 0 ||
parse_tree(side1) < 0 ||
parse_tree(side2) < 0)
return -1;
init_tree_desc(t + 0, merge_base->buffer, merge_base->size);
init_tree_desc(t + 1, side1->buffer, side1->size);
init_tree_desc(t + 2, side2->buffer, side2->size);

View File

@ -951,4 +951,15 @@ test_expect_success '--merge-base with tree OIDs' '
test_cmp with-commits with-trees
'
test_expect_success 'error out on missing tree objects' '
git init --bare missing-tree.git &&
git rev-list side3 >list &&
git rev-parse side3^: >>list &&
git pack-objects missing-tree.git/objects/pack/side3-tree-is-missing <list &&
side3=$(git rev-parse side3) &&
test_must_fail git --git-dir=missing-tree.git merge-tree $side3^ $side3 >actual 2>err &&
test_grep "Could not read $(git rev-parse $side3:)" err &&
test_must_be_empty actual
'
test_done