forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 1
/
worktree_commit_test.go
740 lines (573 loc) · 20.7 KB
/
worktree_commit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
package git
import (
"bytes"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/cache"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/storer"
"github.com/go-git/go-git/v5/storage/filesystem"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/armor"
"github.com/ProtonMail/go-crypto/openpgp/errors"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-billy/v5/util"
. "gopkg.in/check.v1"
)
func (s *WorktreeSuite) TestCommitEmptyOptions(c *C) {
fs := memfs.New()
r, err := Init(memory.NewStorage(), fs)
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
util.WriteFile(fs, "foo", []byte("foo"), 0644)
_, err = w.Add("foo")
c.Assert(err, IsNil)
hash, err := w.Commit("foo", &CommitOptions{})
c.Assert(err, IsNil)
c.Assert(hash.IsZero(), Equals, false)
commit, err := r.CommitObject(hash)
c.Assert(err, IsNil)
c.Assert(commit.Author.Name, Not(Equals), "")
}
func (s *WorktreeSuite) TestCommitInitial(c *C) {
expected := plumbing.NewHash("98c4ac7c29c913f7461eae06e024dc18e80d23a4")
fs := memfs.New()
storage := memory.NewStorage()
r, err := Init(storage, fs)
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
util.WriteFile(fs, "foo", []byte("foo"), 0644)
_, err = w.Add("foo")
c.Assert(err, IsNil)
hash, err := w.Commit("foo\n", &CommitOptions{Author: defaultSignature()})
c.Assert(hash, Equals, expected)
c.Assert(err, IsNil)
assertStorageStatus(c, r, 1, 1, 1, expected)
}
func (s *WorktreeSuite) TestNothingToCommit(c *C) {
expected := plumbing.NewHash("838ea833ce893e8555907e5ef224aa076f5e274a")
r, err := Init(memory.NewStorage(), memfs.New())
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
hash, err := w.Commit("failed empty commit\n", &CommitOptions{Author: defaultSignature()})
c.Assert(hash, Equals, plumbing.ZeroHash)
c.Assert(err, Equals, ErrEmptyCommit)
hash, err = w.Commit("enable empty commits\n", &CommitOptions{Author: defaultSignature(), AllowEmptyCommits: true})
c.Assert(hash, Equals, expected)
c.Assert(err, IsNil)
}
func (s *WorktreeSuite) TestNothingToCommitNonEmptyRepo(c *C) {
fs := memfs.New()
r, err := Init(memory.NewStorage(), fs)
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
err = util.WriteFile(fs, "foo", []byte("foo"), 0644)
c.Assert(err, IsNil)
w.Add("foo")
_, err = w.Commit("previous commit\n", &CommitOptions{Author: defaultSignature()})
c.Assert(err, IsNil)
hash, err := w.Commit("failed empty commit\n", &CommitOptions{Author: defaultSignature()})
c.Assert(hash, Equals, plumbing.ZeroHash)
c.Assert(err, Equals, ErrEmptyCommit)
_, err = w.Commit("enable empty commits\n", &CommitOptions{Author: defaultSignature(), AllowEmptyCommits: true})
c.Assert(err, IsNil)
}
func (s *WorktreeSuite) TestRemoveAndCommitToMakeEmptyRepo(c *C) {
fs := memfs.New()
r, err := Init(memory.NewStorage(), fs)
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
err = util.WriteFile(fs, "foo", []byte("foo"), 0644)
c.Assert(err, IsNil)
_, err = w.Add("foo")
c.Assert(err, IsNil)
_, err = w.Commit("Add in Repo\n", &CommitOptions{Author: defaultSignature()})
c.Assert(err, IsNil)
err = fs.Remove("foo")
c.Assert(err, IsNil)
_, err = w.Add("foo")
c.Assert(err, IsNil)
_, err = w.Commit("Remove foo\n", &CommitOptions{Author: defaultSignature()})
c.Assert(err, IsNil)
}
func (s *WorktreeSuite) TestCommitParent(c *C) {
expected := plumbing.NewHash("ef3ca05477530b37f48564be33ddd48063fc7a22")
fs := memfs.New()
w := &Worktree{
r: s.Repository,
Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
err = util.WriteFile(fs, "foo", []byte("foo"), 0644)
c.Assert(err, IsNil)
_, err = w.Add("foo")
c.Assert(err, IsNil)
hash, err := w.Commit("foo\n", &CommitOptions{Author: defaultSignature()})
c.Assert(hash, Equals, expected)
c.Assert(err, IsNil)
assertStorageStatus(c, s.Repository, 13, 11, 10, expected)
}
func (s *WorktreeSuite) TestCommitAmendWithoutChanges(c *C) {
fs := memfs.New()
w := &Worktree{
r: s.Repository,
Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
err = util.WriteFile(fs, "foo", []byte("foo"), 0644)
c.Assert(err, IsNil)
_, err = w.Add("foo")
c.Assert(err, IsNil)
prevHash, err := w.Commit("foo\n", &CommitOptions{Author: defaultSignature()})
c.Assert(err, IsNil)
amendedHash, err := w.Commit("foo\n", &CommitOptions{Author: defaultSignature(), Amend: true})
c.Assert(err, IsNil)
headRef, err := w.r.Head()
c.Assert(err, IsNil)
c.Assert(amendedHash, Equals, headRef.Hash())
c.Assert(amendedHash, Equals, prevHash)
commit, err := w.r.CommitObject(headRef.Hash())
c.Assert(err, IsNil)
c.Assert(commit.Message, Equals, "foo\n")
assertStorageStatus(c, s.Repository, 13, 11, 10, amendedHash)
}
func (s *WorktreeSuite) TestCommitAmendWithChanges(c *C) {
fs := memfs.New()
w := &Worktree{
r: s.Repository,
Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
util.WriteFile(fs, "foo", []byte("foo"), 0644)
_, err = w.Add("foo")
c.Assert(err, IsNil)
_, err = w.Commit("foo\n", &CommitOptions{Author: defaultSignature()})
c.Assert(err, IsNil)
util.WriteFile(fs, "bar", []byte("bar"), 0644)
_, err = w.Add("bar")
c.Assert(err, IsNil)
amendedHash, err := w.Commit("bar\n", &CommitOptions{Amend: true})
c.Assert(err, IsNil)
headRef, err := w.r.Head()
c.Assert(err, IsNil)
c.Assert(amendedHash, Equals, headRef.Hash())
commit, err := w.r.CommitObject(headRef.Hash())
c.Assert(err, IsNil)
c.Assert(commit.Message, Equals, "bar\n")
c.Assert(commit.NumParents(), Equals, 1)
stats, err := commit.Stats()
c.Assert(err, IsNil)
c.Assert(stats, HasLen, 2)
c.Assert(stats[0], Equals, object.FileStat{
Name: "bar",
Addition: 1,
})
c.Assert(stats[1], Equals, object.FileStat{
Name: "foo",
Addition: 1,
})
assertStorageStatus(c, s.Repository, 14, 12, 11, amendedHash)
}
func (s *WorktreeSuite) TestCommitAmendNothingToCommit(c *C) {
fs := memfs.New()
w := &Worktree{
r: s.Repository,
Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
err = util.WriteFile(fs, "foo", []byte("foo"), 0644)
c.Assert(err, IsNil)
_, err = w.Add("foo")
c.Assert(err, IsNil)
prevHash, err := w.Commit("foo\n", &CommitOptions{Author: defaultSignature()})
c.Assert(err, IsNil)
_, err = w.Commit("bar\n", &CommitOptions{Author: defaultSignature(), AllowEmptyCommits: true})
c.Assert(err, IsNil)
amendedHash, err := w.Commit("foo\n", &CommitOptions{Author: defaultSignature(), Amend: true})
c.Log(prevHash, amendedHash)
c.Assert(err, Equals, ErrEmptyCommit)
c.Assert(amendedHash, Equals, plumbing.ZeroHash)
}
func (s *WorktreeSuite) TestAddAndCommitWithSkipStatus(c *C) {
expected := plumbing.NewHash("375a3808ffde7f129cdd3c8c252fd0fe37cfd13b")
fs := memfs.New()
w := &Worktree{
r: s.Repository,
Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
util.WriteFile(fs, "LICENSE", []byte("foo"), 0644)
util.WriteFile(fs, "foo", []byte("foo"), 0644)
err = w.AddWithOptions(&AddOptions{
Path: "foo",
SkipStatus: true,
})
c.Assert(err, IsNil)
hash, err := w.Commit("commit foo only\n", &CommitOptions{
Author: defaultSignature(),
})
c.Assert(hash, Equals, expected)
c.Assert(err, IsNil)
assertStorageStatus(c, s.Repository, 13, 11, 10, expected)
}
func (s *WorktreeSuite) TestAddAndCommitWithSkipStatusPathNotModified(c *C) {
expected := plumbing.NewHash("375a3808ffde7f129cdd3c8c252fd0fe37cfd13b")
expected2 := plumbing.NewHash("8691273baf8f6ee2cccfc05e910552c04d02d472")
fs := memfs.New()
w := &Worktree{
r: s.Repository,
Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
util.WriteFile(fs, "foo", []byte("foo"), 0644)
status, err := w.Status()
c.Assert(err, IsNil)
foo := status.File("foo")
c.Assert(foo.Staging, Equals, Untracked)
c.Assert(foo.Worktree, Equals, Untracked)
err = w.AddWithOptions(&AddOptions{
Path: "foo",
SkipStatus: true,
})
c.Assert(err, IsNil)
status, err = w.Status()
c.Assert(err, IsNil)
foo = status.File("foo")
c.Assert(foo.Staging, Equals, Added)
c.Assert(foo.Worktree, Equals, Unmodified)
hash, err := w.Commit("commit foo only\n", &CommitOptions{All: true,
Author: defaultSignature(),
})
c.Assert(hash, Equals, expected)
c.Assert(err, IsNil)
commit1, err := w.r.CommitObject(hash)
c.Assert(err, IsNil)
status, err = w.Status()
c.Assert(err, IsNil)
foo = status.File("foo")
c.Assert(foo.Staging, Equals, Untracked)
c.Assert(foo.Worktree, Equals, Untracked)
assertStorageStatus(c, s.Repository, 13, 11, 10, expected)
err = w.AddWithOptions(&AddOptions{
Path: "foo",
SkipStatus: true,
})
c.Assert(err, IsNil)
status, err = w.Status()
c.Assert(err, IsNil)
foo = status.File("foo")
c.Assert(foo.Staging, Equals, Untracked)
c.Assert(foo.Worktree, Equals, Untracked)
hash, err = w.Commit("commit with no changes\n", &CommitOptions{
Author: defaultSignature(),
AllowEmptyCommits: true,
})
c.Assert(hash, Equals, expected2)
c.Assert(err, IsNil)
commit2, err := w.r.CommitObject(hash)
c.Assert(err, IsNil)
status, err = w.Status()
c.Assert(err, IsNil)
foo = status.File("foo")
c.Assert(foo.Staging, Equals, Untracked)
c.Assert(foo.Worktree, Equals, Untracked)
patch, err := commit2.Patch(commit1)
c.Assert(err, IsNil)
files := patch.FilePatches()
c.Assert(files, IsNil)
assertStorageStatus(c, s.Repository, 13, 11, 11, expected2)
}
func (s *WorktreeSuite) TestCommitAll(c *C) {
expected := plumbing.NewHash("aede6f8c9c1c7ec9ca8d287c64b8ed151276fa28")
fs := memfs.New()
w := &Worktree{
r: s.Repository,
Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
util.WriteFile(fs, "LICENSE", []byte("foo"), 0644)
util.WriteFile(fs, "foo", []byte("foo"), 0644)
hash, err := w.Commit("foo\n", &CommitOptions{
All: true,
Author: defaultSignature(),
})
c.Assert(hash, Equals, expected)
c.Assert(err, IsNil)
assertStorageStatus(c, s.Repository, 13, 11, 10, expected)
}
func (s *WorktreeSuite) TestRemoveAndCommitAll(c *C) {
expected := plumbing.NewHash("907cd576c6ced2ecd3dab34a72bf9cf65944b9a9")
fs := memfs.New()
w := &Worktree{
r: s.Repository,
Filesystem: fs,
}
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
util.WriteFile(fs, "foo", []byte("foo"), 0644)
_, err = w.Add("foo")
c.Assert(err, IsNil)
_, errFirst := w.Commit("Add in Repo\n", &CommitOptions{
Author: defaultSignature(),
})
c.Assert(errFirst, IsNil)
errRemove := fs.Remove("foo")
c.Assert(errRemove, IsNil)
hash, errSecond := w.Commit("Remove foo\n", &CommitOptions{
All: true,
Author: defaultSignature(),
})
c.Assert(errSecond, IsNil)
c.Assert(hash, Equals, expected)
c.Assert(err, IsNil)
assertStorageStatus(c, s.Repository, 13, 11, 11, expected)
}
func (s *WorktreeSuite) TestCommitSign(c *C) {
fs := memfs.New()
storage := memory.NewStorage()
r, err := Init(storage, fs)
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
util.WriteFile(fs, "foo", []byte("foo"), 0644)
_, err = w.Add("foo")
c.Assert(err, IsNil)
key := commitSignKey(c, true)
hash, err := w.Commit("foo\n", &CommitOptions{Author: defaultSignature(), SignKey: key})
c.Assert(err, IsNil)
// Verify the commit.
pks := new(bytes.Buffer)
pkw, err := armor.Encode(pks, openpgp.PublicKeyType, nil)
c.Assert(err, IsNil)
err = key.Serialize(pkw)
c.Assert(err, IsNil)
err = pkw.Close()
c.Assert(err, IsNil)
expectedCommit, err := r.CommitObject(hash)
c.Assert(err, IsNil)
actual, err := expectedCommit.Verify(pks.String())
c.Assert(err, IsNil)
c.Assert(actual.PrimaryKey, DeepEquals, key.PrimaryKey)
}
func (s *WorktreeSuite) TestCommitSignBadKey(c *C) {
fs := memfs.New()
storage := memory.NewStorage()
r, err := Init(storage, fs)
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
util.WriteFile(fs, "foo", []byte("foo"), 0644)
_, err = w.Add("foo")
c.Assert(err, IsNil)
key := commitSignKey(c, false)
_, err = w.Commit("foo\n", &CommitOptions{Author: defaultSignature(), SignKey: key})
c.Assert(err, Equals, errors.InvalidArgumentError("signing key is encrypted"))
}
func (s *WorktreeSuite) TestCommitTreeSort(c *C) {
fs, clean := s.TemporalFilesystem()
defer clean()
st := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
_, err := Init(st, nil)
c.Assert(err, IsNil)
r, _ := Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
URL: fs.Root(),
})
w, err := r.Worktree()
c.Assert(err, IsNil)
mfs := w.Filesystem
err = mfs.MkdirAll("delta", 0755)
c.Assert(err, IsNil)
for _, p := range []string{"delta_last", "Gamma", "delta/middle", "Beta", "delta-first", "alpha"} {
util.WriteFile(mfs, p, []byte("foo"), 0644)
_, err = w.Add(p)
c.Assert(err, IsNil)
}
_, err = w.Commit("foo\n", &CommitOptions{
All: true,
Author: defaultSignature(),
})
c.Assert(err, IsNil)
err = r.Push(&PushOptions{})
c.Assert(err, IsNil)
cmd := exec.Command("git", "fsck")
cmd.Dir = fs.Root()
cmd.Env = os.Environ()
buf := &bytes.Buffer{}
cmd.Stderr = buf
cmd.Stdout = buf
err = cmd.Run()
c.Assert(err, IsNil, Commentf("%s", buf.Bytes()))
}
// https://github.com/go-git/go-git/pull/224
func (s *WorktreeSuite) TestJustStoreObjectsNotAlreadyStored(c *C) {
fs, clean := s.TemporalFilesystem()
defer clean()
fsDotgit, err := fs.Chroot(".git") // real fs to get modified timestamps
c.Assert(err, IsNil)
storage := filesystem.NewStorage(fsDotgit, cache.NewObjectLRUDefault())
r, err := Init(storage, fs)
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
// Step 1: Write LICENSE
util.WriteFile(fs, "LICENSE", []byte("license"), 0644)
hLicense, err := w.Add("LICENSE")
c.Assert(err, IsNil)
c.Assert(hLicense, Equals, plumbing.NewHash("0484eba0d41636ba71fa612c78559cd6c3006cde"))
hash, err := w.Commit("commit 1\n", &CommitOptions{
All: true,
Author: defaultSignature(),
})
c.Assert(err, IsNil)
c.Assert(hash, Equals, plumbing.NewHash("7a7faee4630d2664a6869677cc8ab614f3fd4a18"))
infoLicense, err := fsDotgit.Stat(filepath.Join("objects", "04", "84eba0d41636ba71fa612c78559cd6c3006cde"))
c.Assert(err, IsNil) // checking objects file exists
// Step 2: Write foo.
time.Sleep(5 * time.Millisecond) // uncool, but we need to get different timestamps...
util.WriteFile(fs, "foo", []byte("foo"), 0644)
hFoo, err := w.Add("foo")
c.Assert(err, IsNil)
c.Assert(hFoo, Equals, plumbing.NewHash("19102815663d23f8b75a47e7a01965dcdc96468c"))
hash, err = w.Commit("commit 2\n", &CommitOptions{
All: true,
Author: defaultSignature(),
})
c.Assert(err, IsNil)
c.Assert(hash, Equals, plumbing.NewHash("97c0c5177e6ac57d10e8ea0017f2d39b91e2b364"))
// Step 3: Check
// There is no need to overwrite the object of LICENSE, because its content
// was not changed. Just a write on the object of foo is required. This behaviour
// is fixed by #224 and tested by comparing the timestamps of the stored objects.
infoFoo, err := fsDotgit.Stat(filepath.Join("objects", "19", "102815663d23f8b75a47e7a01965dcdc96468c"))
c.Assert(err, IsNil) // checking objects file exists
c.Assert(infoLicense.ModTime().Before(infoFoo.ModTime()), Equals, true) // object of foo has another/greaterThan timestamp than LICENSE
infoLicenseSecond, err := fsDotgit.Stat(filepath.Join("objects", "04", "84eba0d41636ba71fa612c78559cd6c3006cde"))
c.Assert(err, IsNil)
log.Printf("comparing mod time: %v == %v on %v (%v)", infoLicenseSecond.ModTime(), infoLicense.ModTime(), runtime.GOOS, runtime.GOARCH)
c.Assert(infoLicenseSecond.ModTime(), Equals, infoLicense.ModTime()) // object of LICENSE should have the same timestamp because no additional write operation was performed
}
func assertStorageStatus(
c *C, r *Repository,
treesCount, blobCount, commitCount int, head plumbing.Hash,
) {
trees, err := r.Storer.IterEncodedObjects(plumbing.TreeObject)
c.Assert(err, IsNil)
blobs, err := r.Storer.IterEncodedObjects(plumbing.BlobObject)
c.Assert(err, IsNil)
commits, err := r.Storer.IterEncodedObjects(plumbing.CommitObject)
c.Assert(err, IsNil)
c.Assert(lenIterEncodedObjects(trees), Equals, treesCount)
c.Assert(lenIterEncodedObjects(blobs), Equals, blobCount)
c.Assert(lenIterEncodedObjects(commits), Equals, commitCount)
ref, err := r.Head()
c.Assert(err, IsNil)
c.Assert(ref.Hash(), Equals, head)
}
func lenIterEncodedObjects(iter storer.EncodedObjectIter) int {
count := 0
iter.ForEach(func(plumbing.EncodedObject) error {
count++
return nil
})
return count
}
func defaultSignature() *object.Signature {
when, _ := time.Parse(object.DateFormat, "Thu May 04 00:03:43 2017 +0200")
return &object.Signature{
Name: "foo",
Email: "[email protected]",
When: when,
}
}
func commitSignKey(c *C, decrypt bool) *openpgp.Entity {
s := strings.NewReader(armoredKeyRing)
es, err := openpgp.ReadArmoredKeyRing(s)
c.Assert(err, IsNil)
c.Assert(es, HasLen, 1)
c.Assert(es[0].Identities, HasLen, 1)
_, ok := es[0].Identities["foo bar <[email protected]>"]
c.Assert(ok, Equals, true)
key := es[0]
if decrypt {
err = key.PrivateKey.Decrypt([]byte(keyPassphrase))
c.Assert(err, IsNil)
}
return key
}
const armoredKeyRing = `
-----BEGIN PGP PRIVATE KEY BLOCK-----
lQdGBFt89QIBEAC8du0Purt9yeFuLlBYHcexnZvcbaci2pY+Ejn1VnxM7caFxRX/
b2weZi9E6+I0F+K/hKIaidPdcbK92UCL0Vp6F3izjqategZ7o44vlK/HfWFME4wv
sou6lnig9ovA73HRyzngi3CmqWxSdg8lL0kIJLNzlvCFEd4Z34BnEkagklQJRymo
0WnmLJjSnZFT5Nk7q5jrcR7ApbD98cakvgivDlUBPJCk2JFPWheCkouWPHMvLXQz
bZXW5RFz4lJsMUWa/S3ofvIOnjG5Etnil3IA4uksS8fSDkGus998mBvUwzqX7xBh
dK17ZEbxDdO4PuVJDkjvq618rMu8FVk5yVd59rUketSnGrehd/+vdh6qtgQC4tu1
RldbUVAuKZGg79H61nWnvrDZmbw4eoqCEuv1+aZsM9ElSC5Ps2J0rtpHRyBndKn+
8Jlc/KTH04/O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