MCPcopy Create free account
hub / github.com/go-git/go-git / TestJustStoreObjectsNotAlreadyStored

Method TestJustStoreObjectsNotAlreadyStored

worktree_commit_test.go:445–502  ·  view source on GitHub ↗

https://github.com/go-git/go-git/pull/224

(c *C)

Source from the content-addressed store, hash-verified

443
444// https://github.com/go-git/go-git/pull/224
445func (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}

Callers

nothing calls this directly

Calls 13

NewStorageFunction · 0.92
NewObjectLRUDefaultFunction · 0.92
NewHashFunction · 0.92
InitFunction · 0.85
defaultSignatureFunction · 0.85
ChrootMethod · 0.80
WorktreeMethod · 0.80
StatMethod · 0.80
JoinMethod · 0.80
PrintfMethod · 0.80
CommitMethod · 0.65
TemporalFilesystemMethod · 0.45

Tested by

no test coverage detected