MCPcopy
hub / github.com/go-git/go-git / TestTreeEncodePreservesDuplicateEntries

Function TestTreeEncodePreservesDuplicateEntries

plumbing/object/tree_test.go:2027–2060  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2025}
2026
2027func TestTreeEncodePreservesDuplicateEntries(t *testing.T) {
2028 t.Parallel()
2029
2030 hashABytes := bytes.Repeat([]byte{0xAA}, 20)
2031 hashBBytes := bytes.Repeat([]byte{0xBB}, 20)
2032 var hashA, hashB plumbing.Hash
2033 copy(hashA[:], hashABytes)
2034 copy(hashB[:], hashBBytes)
2035
2036 tree := &Tree{
2037 Entries: []TreeEntry{
2038 {Name: "foo", Mode: filemode.Regular, Hash: hashA},
2039 {Name: "foo", Mode: filemode.Regular, Hash: hashB},
2040 },
2041 }
2042
2043 obj := &plumbing.MemoryObject{}
2044 require.NoError(t, tree.Encode(obj))
2045
2046 r, err := obj.Reader()
2047 require.NoError(t, err)
2048 got, err := io.ReadAll(r)
2049 require.NoError(t, err)
2050 require.NoError(t, r.Close())
2051
2052 var want bytes.Buffer
2053 want.WriteString("100644 foo")
2054 want.WriteByte(0)
2055 want.Write(hashABytes)
2056 want.WriteString("100644 foo")
2057 want.WriteByte(0)
2058 want.Write(hashBBytes)
2059 assert.Equal(t, want.Bytes(), got)
2060}

Callers

nothing calls this directly

Calls 5

EncodeMethod · 0.95
ReaderMethod · 0.95
CloseMethod · 0.65
WriteMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…