Skip to content

Commit

Permalink
Split TestMissingObjects
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spraints committed Nov 8, 2024
1 parent 1b02164 commit 5417514
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
45 changes: 41 additions & 4 deletions internal/integration/missingobjects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
)

func TestMissingObjects(t *testing.T) {
const refToCreate = "refs/heads/new-branch"

x := setUpMissingObjectsTestRepo(t)
testRepo := x.TestRepo
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions internal/integration/testdata/set-up-missing-objects-push
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ printf '{"push_from":"%s","push_to":"%s","ref":"refs/heads/%s","extra_ref":"refs
printf "^%s\n%s\n" "$COMMIT_B" "$COMMIT_C" \
| git pack-objects --revs --stdout >../bad.pack

# Make an empty pack.
git pack-objects --stdout </dev/null >../empty.pack

cd ..
rm -rf work.git

Expand Down

0 comments on commit 5417514

Please sign in to comment.