@@ -15,6 +15,44 @@ import (
1515 "github.com/stretchr/testify/require"
1616)
1717
18+ const roundTripCommitSha string = `561ed224a6bd39232d902ad8023c0ebe44fbf6c5`
19+ const roundTripCommit string = `tree f2ebdf9c967f69d57b370901f9344596ec47e51c
20+ parent fe8fbf7de1cd9f08ae642e502bf5de94e523cc08
21+ author brian m. carlson <bk2204@github.com> 1543506816 +0000
22+ committer brian m. carlson <bk2204@github.com> 1543506816 +0000
23+ gpgsig -----BEGIN PGP SIGNATURE-----
24+ Version: GnuPG/MacGPG2 v2.2.9 (Darwin)
25+
26+ iQIGBAABCgAwFiEETbktHYzuflTwZxNFLQybwS+Cs6EFAlwAC4cSHGJrMjIwNEBn
27+ aXRodWIuY29tAAoJEC0Mm8EvgrOhiRMN/2rTxkBb5BeQQeq7rPiIW8+29FzuvPeD
28+ /DhxlRKwKut9h4qhtxNQszTezxhP4PLOkuMvUax2pGXCQ8cjkSswagmycev+AB4d
29+ s0loG4SrEwvH8nAdr6qfNx4ZproRJ8QaEJqyN9SqF7PCWrUAoJKehdgA38WtYFws
30+ ON+nIwzDIvgpoNI+DzgWrx16SOTp87xt8RaJOVK9JNZQk8zBh7rR2viS9CWLysmz
31+ wOh3j4XI1TZ5IFJfpCxZzUDFgb6K3wpAX6Vux5F1f3cN5MsJn6WUJCmYCvwofeeZ
32+ 6LMqKgry7EA12l7Tv/JtmMeh+rbT5WLdMIsjascUaHRhpJDNqqHCKMEj1zh3QZNY
33+ Hycdcs24JouVAtPwg07f1ncPU3aE624LnNRA9A6Ih6SkkKE4tgMVA5qkObDfwzLE
34+ lWyBj2QKySaIdSlU2EcoH3UK33v/ofrRr3+bUkDgxdqeV/RkBVvfpeMwFVSFWseE
35+ bCcotryLCZF7vBQU+pKC+EaZxQV9L5+McGzcDYxUmqrhwtR+azRBYFOw+lOT4sYD
36+ FxdLFWCtmDhKPX5Ajci2gmyfgCwdIeDhSuOf2iQQGRpE6y7aka4AlaE=
37+ =UyqL
38+ -----END PGP SIGNATURE-----
39+
40+ pack/set: ignore packs without indices
41+
42+ When we look for packs to read, we look for a pack file, and then an
43+ index, and fail if either one is missing. When Git looks for packs to
44+ read, it looks only for indices and then checks if the pack is present.
45+
46+ The Git approach handles the case when there is an extra pack that lacks
47+ an index, while our approach does not. Consequently, we can get various
48+ errors (showing up so far only on Windows) when an index is missing.
49+
50+ If the index file cannot be read for any reason, simply skip the entire
51+ pack altogether and continue on. This leaves us no more or less
52+ functional than Git in terms of discovering objects and makes our error
53+ handling more robust.
54+ `
55+
1856func TestDecodeObject (t * testing.T ) {
1957 sha := "af5626b4a114abcb82d63db7c8082c3c4756e51b"
2058 contents := "Hello, world!\n "
@@ -223,6 +261,28 @@ func TestWriteCommit(t *testing.T) {
223261 assert .NotNil (t , s .(* memoryStorer ).fs [hex .EncodeToString (sha )])
224262}
225263
264+ func TestWriteCommitWithGPGSignature (t * testing.T ) {
265+ b , err := NewMemoryBackend (nil )
266+ require .NoError (t , err )
267+
268+ odb , err := FromBackend (b )
269+ require .NoError (t , err )
270+
271+ commit := new (Commit )
272+ _ , err = commit .Decode (
273+ strings .NewReader (roundTripCommit ), int64 (len (roundTripCommit )))
274+ require .NoError (t , err )
275+
276+ buf := new (bytes.Buffer )
277+ commit .Encode (buf )
278+ assert .Equal (t , roundTripCommit , buf .String ())
279+
280+ sha , err := odb .WriteCommit (commit )
281+
282+ assert .Nil (t , err )
283+ assert .Equal (t , roundTripCommitSha , hex .EncodeToString (sha ))
284+ }
285+
226286func TestDecodeTag (t * testing.T ) {
227287 const sha = "7639ba293cd2c457070e8446ecdea56682af0f48"
228288 tagShaHex , err := hex .DecodeString (sha )
0 commit comments