https://github.com/go-git/go-git/pull/224
(c *C)
| 562 | |
| 563 | // https://github.com/go-git/go-git/pull/224 |
| 564 | func (s *WorktreeSuite) TestJustStoreObjectsNotAlreadyStored(c *C) { |
| 565 | fs := s.TemporalFilesystem(c) |
| 566 | |
| 567 | fsDotgit, err := fs.Chroot(".git") // real fs to get modified timestamps |
| 568 | c.Assert(err, IsNil) |
| 569 | storage := filesystem.NewStorage(fsDotgit, cache.NewObjectLRUDefault()) |
| 570 | |
| 571 | r, err := Init(storage, fs) |
| 572 | c.Assert(err, IsNil) |
| 573 | |
| 574 | w, err := r.Worktree() |
| 575 | c.Assert(err, IsNil) |
| 576 | |
| 577 | // Step 1: Write LICENSE |
| 578 | util.WriteFile(fs, "LICENSE", []byte("license"), 0644) |
| 579 | hLicense, err := w.Add("LICENSE") |
| 580 | c.Assert(err, IsNil) |
| 581 | c.Assert(hLicense, Equals, plumbing.NewHash("0484eba0d41636ba71fa612c78559cd6c3006cde")) |
| 582 | |
| 583 | hash, err := w.Commit("commit 1\n", &CommitOptions{ |
| 584 | All: true, |
| 585 | Author: defaultSignature(), |
| 586 | }) |
| 587 | c.Assert(err, IsNil) |
| 588 | c.Assert(hash, Equals, plumbing.NewHash("7a7faee4630d2664a6869677cc8ab614f3fd4a18")) |
| 589 | |
| 590 | infoLicense, err := fsDotgit.Stat(filepath.Join("objects", "04", "84eba0d41636ba71fa612c78559cd6c3006cde")) |
| 591 | c.Assert(err, IsNil) // checking objects file exists |
| 592 | |
| 593 | // Step 2: Write foo. |
| 594 | time.Sleep(5 * time.Millisecond) // uncool, but we need to get different timestamps... |
| 595 | util.WriteFile(fs, "foo", []byte("foo"), 0644) |
| 596 | hFoo, err := w.Add("foo") |
| 597 | c.Assert(err, IsNil) |
| 598 | c.Assert(hFoo, Equals, plumbing.NewHash("19102815663d23f8b75a47e7a01965dcdc96468c")) |
| 599 | |
| 600 | hash, err = w.Commit("commit 2\n", &CommitOptions{ |
| 601 | All: true, |
| 602 | Author: defaultSignature(), |
| 603 | }) |
| 604 | c.Assert(err, IsNil) |
| 605 | c.Assert(hash, Equals, plumbing.NewHash("97c0c5177e6ac57d10e8ea0017f2d39b91e2b364")) |
| 606 | |
| 607 | // Step 3: Check |
| 608 | // There is no need to overwrite the object of LICENSE, because its content |
| 609 | // was not changed. Just a write on the object of foo is required. This behaviour |
| 610 | // is fixed by #224 and tested by comparing the timestamps of the stored objects. |
| 611 | infoFoo, err := fsDotgit.Stat(filepath.Join("objects", "19", "102815663d23f8b75a47e7a01965dcdc96468c")) |
| 612 | c.Assert(err, IsNil) // checking objects file exists |
| 613 | c.Assert(infoLicense.ModTime().Before(infoFoo.ModTime()), Equals, true) // object of foo has another/greaterThan timestamp than LICENSE |
| 614 | |
| 615 | infoLicenseSecond, err := fsDotgit.Stat(filepath.Join("objects", "04", "84eba0d41636ba71fa612c78559cd6c3006cde")) |
| 616 | c.Assert(err, IsNil) |
| 617 | |
| 618 | log.Printf("comparing mod time: %v == %v on %v (%v)", infoLicenseSecond.ModTime(), infoLicense.ModTime(), runtime.GOOS, runtime.GOARCH) |
| 619 | c.Assert(infoLicenseSecond.ModTime(), Equals, infoLicense.ModTime()) // object of LICENSE should have the same timestamp because no additional write operation was performed |
| 620 | } |
| 621 |
nothing calls this directly
no test coverage detected