Skip to content

Commit c428812

Browse files
committed
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.
1 parent 1b02164 commit c428812

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

internal/integration/missingobjects_test.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
)
2020

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

2423
x := setUpMissingObjectsTestRepo(t)
2524
testRepo := x.TestRepo
@@ -48,9 +47,48 @@ func TestMissingObjects(t *testing.T) {
4847
// Try to update the ref that's already there to commit C (but we won't
4948
// push its parent and the remote doesn't have the parent either).
5049
{info.OldOID, info.NewOID, info.Ref},
50+
},
51+
pack,
52+
)
53+
54+
refStatus, unpackRes, _, err := readResult(t, srp.Out)
55+
require.NoError(t, err)
56+
assert.Equal(t, map[string]string{
57+
info.Ref: "ng missing necessary objects",
58+
}, refStatus)
59+
assert.Equal(t, "unpack ok\n", unpackRes)
60+
}
61+
62+
func TestDeleteAndUpdate(t *testing.T) {
63+
const refToCreate = "refs/heads/new-branch"
64+
65+
x := setUpMissingObjectsTestRepo(t)
66+
testRepo := x.TestRepo
67+
info := x.Info
68+
69+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
70+
defer cancel()
71+
72+
srp := startSpokesReceivePack(ctx, t, testRepo)
73+
74+
refs, _, err := readAdv(srp.Out)
75+
require.NoError(t, err)
76+
assert.Equal(t, refs, map[string]string{
77+
info.Ref: info.OldOID,
78+
info.DelRef: info.OldOID,
79+
})
80+
81+
// Send the pack that's missing a commit.
82+
pack, err := os.Open("testdata/missing-objects/empty.pack")
83+
require.NoError(t, err)
84+
defer pack.Close()
85+
86+
writePushData(
87+
t, srp,
88+
[]refUpdate{
5189
// Try to create another ref with a commit that the remote already has.
5290
{objectformat.NullOIDSHA1, info.OldOID, refToCreate},
53-
// Try to delete another ref.
91+
// Try to delete a ref.
5492
{info.OldOID, objectformat.NullOIDSHA1, info.DelRef},
5593
},
5694
pack,
@@ -59,9 +97,8 @@ func TestMissingObjects(t *testing.T) {
5997
refStatus, unpackRes, _, err := readResult(t, srp.Out)
6098
require.NoError(t, err)
6199
assert.Equal(t, map[string]string{
62-
info.Ref: "ng missing necessary objects",
63-
info.DelRef: "ok",
64100
refToCreate: "ok",
101+
info.DelRef: "ok",
65102
}, refStatus)
66103
assert.Equal(t, "unpack ok\n", unpackRes)
67104
}
32 Bytes
Binary file not shown.

internal/integration/testdata/set-up-missing-objects-push

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ printf '{"push_from":"%s","push_to":"%s","ref":"refs/heads/%s","extra_ref":"refs
8080
printf "^%s\n%s\n" "$COMMIT_B" "$COMMIT_C" \
8181
| git pack-objects --revs --stdout >../bad.pack
8282

83+
# Make an empty pack.
84+
git pack-objects --stdout </dev/null >../empty.pack
85+
8386
cd ..
8487
rm -rf work.git
8588

0 commit comments

Comments
 (0)