From 5417514fdb914f47541a487574ebff5e340cb8c6 Mon Sep 17 00:00:00 2001 From: Matt Burke Date: Fri, 8 Nov 2024 11:56:08 -0500 Subject: [PATCH] Split TestMissingObjects Pushing an empty pack should be fine. There was an earlier issue where deleting refs didn't work because we tried looking for objects in the uploaded pack and didn't find any. So we do want to preserve that functionality. We also should be able to accept new refs that point to commits that are already on the server. missing objects are actually bad, so we don't need to have pushes work when a partial graph is supplied. For now, the push still appears to succeed, but in the next step it won't. --- internal/integration/missingobjects_test.go | 45 ++++++++++++++++-- .../testdata/missing-objects/empty.pack | Bin 0 -> 32 bytes .../testdata/set-up-missing-objects-push | 3 ++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 internal/integration/testdata/missing-objects/empty.pack diff --git a/internal/integration/missingobjects_test.go b/internal/integration/missingobjects_test.go index e6ef6aa..e9b7354 100644 --- a/internal/integration/missingobjects_test.go +++ b/internal/integration/missingobjects_test.go @@ -19,7 +19,6 @@ import ( ) func TestMissingObjects(t *testing.T) { - const refToCreate = "refs/heads/new-branch" x := setUpMissingObjectsTestRepo(t) testRepo := x.TestRepo @@ -48,9 +47,48 @@ func TestMissingObjects(t *testing.T) { // Try to update the ref that's already there to commit C (but we won't // push its parent and the remote doesn't have the parent either). {info.OldOID, info.NewOID, info.Ref}, + }, + pack, + ) + + refStatus, unpackRes, _, err := readResult(t, srp.Out) + require.NoError(t, err) + assert.Equal(t, map[string]string{ + info.Ref: "ng missing necessary objects", + }, refStatus) + assert.Equal(t, "unpack ok\n", unpackRes) +} + +func TestDeleteAndUpdate(t *testing.T) { + const refToCreate = "refs/heads/new-branch" + + x := setUpMissingObjectsTestRepo(t) + testRepo := x.TestRepo + info := x.Info + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + srp := startSpokesReceivePack(ctx, t, testRepo) + + refs, _, err := readAdv(srp.Out) + require.NoError(t, err) + assert.Equal(t, refs, map[string]string{ + info.Ref: info.OldOID, + info.DelRef: info.OldOID, + }) + + // Send the pack that's missing a commit. + pack, err := os.Open("testdata/missing-objects/empty.pack") + require.NoError(t, err) + defer pack.Close() + + writePushData( + t, srp, + []refUpdate{ // Try to create another ref with a commit that the remote already has. - {objectformat.NullOIDSHA1, info.OldOID, refToCreate}, - // Try to delete another ref. + {objectformat.NullOIDSHA1, info.OldOID, "refs/heads/new-branch"}, + // Try to delete a ref. {info.OldOID, objectformat.NullOIDSHA1, info.DelRef}, }, pack, @@ -61,7 +99,6 @@ func TestMissingObjects(t *testing.T) { assert.Equal(t, map[string]string{ info.Ref: "ng missing necessary objects", info.DelRef: "ok", - refToCreate: "ok", }, refStatus) assert.Equal(t, "unpack ok\n", unpackRes) } diff --git a/internal/integration/testdata/missing-objects/empty.pack b/internal/integration/testdata/missing-objects/empty.pack new file mode 100644 index 0000000000000000000000000000000000000000..dc270159c10266fdd2c21f1d16288f0da18ca30f GIT binary patch literal 32 mcmWG=boORoU|<4b2Bx_jP1ZM7yxJ../bad.pack +# Make an empty pack. +git pack-objects --stdout ../empty.pack + cd .. rm -rf work.git