Message ID | 11b9cd8c5da5e6792ce940ea29d2e93e57731555.1708612605.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | merge-tree: handle missing objects correctly | expand |
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes: > - 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; Obviously good. > diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh > index 7d0fa74da74..908c9b540c8 100755 > --- a/t/t4301-merge-tree-write-tree.sh > +++ b/t/t4301-merge-tree-write-tree.sh > @@ -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 > +' I very much like the way this test emulates an operation in a repository that lack certaion objects so cleanly, and wish we had used this pattern instead of poking at loose object files in hundreds of existing tests (#leftoverbits obviously). It also justifies why a silent "return -1" in the patch is sufficient ;-) Thanks.
diff --git a/merge-ort.c b/merge-ort.c index 6491070d965..c37fc035f13 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -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); diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index 7d0fa74da74..908c9b540c8 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -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