https://github.com/go-git/go-git/pull/224
(c *C)
| 443 | |
| 444 | // https://github.com/go-git/go-git/pull/224 |
| 445 | func (s *WorktreeSuite) TestJustStoreObjectsNotAlreadyStored(c *C) { |
| 446 | fs, clean := s.TemporalFilesystem() |
| 447 | defer clean() |
| 448 | |
| 449 | fsDotgit, err := fs.Chroot(".git") // real fs to get modified timestamps |
| 450 | c.Assert(err, IsNil) |
| 451 | storage := filesystem.NewStorage(fsDotgit, cache.NewObjectLRUDefault()) |
| 452 | |
| 453 | r, err := Init(storage, fs) |
| 454 | c.Assert(err, IsNil) |
| 455 | |
| 456 | w, err := r.Worktree() |
| 457 | c.Assert(err, IsNil) |
| 458 | |
| 459 | // Step 1: Write LICENSE |
| 460 | util.WriteFile(fs, "LICENSE", []byte("license"), 0644) |
| 461 | hLicense, err := w.Add("LICENSE") |
| 462 | c.Assert(err, IsNil) |
| 463 | c.Assert(hLicense, Equals, plumbing.NewHash("0484eba0d41636ba71fa612c78559cd6c3006cde")) |
| 464 | |
| 465 | hash, err := w.Commit("commit 1\n", &CommitOptions{ |
| 466 | All: true, |
| 467 | Author: defaultSignature(), |
| 468 | }) |
| 469 | c.Assert(err, IsNil) |
| 470 | c.Assert(hash, Equals, plumbing.NewHash("7a7faee4630d2664a6869677cc8ab614f3fd4a18")) |
| 471 | |
| 472 | infoLicense, err := fsDotgit.Stat(filepath.Join("objects", "04", "84eba0d41636ba71fa612c78559cd6c3006cde")) |
| 473 | c.Assert(err, IsNil) // checking objects file exists |
| 474 | |
| 475 | // Step 2: Write foo. |
| 476 | time.Sleep(5 * time.Millisecond) // uncool, but we need to get different timestamps... |
| 477 | util.WriteFile(fs, "foo", []byte("foo"), 0644) |
| 478 | hFoo, err := w.Add("foo") |
| 479 | c.Assert(err, IsNil) |
| 480 | c.Assert(hFoo, Equals, plumbing.NewHash("19102815663d23f8b75a47e7a01965dcdc96468c")) |
| 481 | |
| 482 | hash, err = w.Commit("commit 2\n", &CommitOptions{ |
| 483 | All: true, |
| 484 | Author: defaultSignature(), |
| 485 | }) |
| 486 | c.Assert(err, IsNil) |
| 487 | c.Assert(hash, Equals, plumbing.NewHash("97c0c5177e6ac57d10e8ea0017f2d39b91e2b364")) |
| 488 | |
| 489 | // Step 3: Check |
| 490 | // There is no need to overwrite the object of LICENSE, because its content |
| 491 | // was not changed. Just a write on the object of foo is required. This behaviour |
| 492 | // is fixed by #224 and tested by comparing the timestamps of the stored objects. |
| 493 | infoFoo, err := fsDotgit.Stat(filepath.Join("objects", "19", "102815663d23f8b75a47e7a01965dcdc96468c")) |
| 494 | c.Assert(err, IsNil) // checking objects file exists |
| 495 | c.Assert(infoLicense.ModTime().Before(infoFoo.ModTime()), Equals, true) // object of foo has another/greaterThan timestamp than LICENSE |
| 496 | |
| 497 | infoLicenseSecond, err := fsDotgit.Stat(filepath.Join("objects", "04", "84eba0d41636ba71fa612c78559cd6c3006cde")) |
| 498 | c.Assert(err, IsNil) |
| 499 | |
| 500 | log.Printf("comparing mod time: %v == %v on %v (%v)", infoLicenseSecond.ModTime(), infoLicense.ModTime(), runtime.GOOS, runtime.GOARCH) |
| 501 | c.Assert(infoLicenseSecond.ModTime(), Equals, infoLicense.ModTime()) // object of LICENSE should have the same timestamp because no additional write operation was performed |
| 502 | } |
nothing calls this directly
no test coverage detected