-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #941 from djmoch/filestats-rename
plumbing: object, enable renames in getFileStatsFromFilePatches
- Loading branch information
Showing
2 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package object_test | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/go-git/go-billy/v5/memfs" | ||
"github.com/go-git/go-billy/v5/util" | ||
"github.com/go-git/go-git/v5" | ||
"github.com/go-git/go-git/v5/plumbing/object" | ||
"github.com/go-git/go-git/v5/storage/memory" | ||
|
||
fixtures "github.com/go-git/go-git-fixtures/v4" | ||
. "gopkg.in/check.v1" | ||
) | ||
|
||
type PatchStatsSuite struct { | ||
fixtures.Suite | ||
} | ||
|
||
var _ = Suite(&PatchStatsSuite{}) | ||
|
||
func (s *PatchStatsSuite) TestStatsWithRename(c *C) { | ||
cm := &git.CommitOptions{ | ||
Author: &object.Signature{Name: "Foo", Email: "[email protected]", When: time.Now()}, | ||
} | ||
|
||
fs := memfs.New() | ||
r, err := git.Init(memory.NewStorage(), fs) | ||
c.Assert(err, IsNil) | ||
|
||
w, err := r.Worktree() | ||
c.Assert(err, IsNil) | ||
|
||
util.WriteFile(fs, "foo", []byte("foo\nbar\n"), 0644) | ||
|
||
_, err = w.Add("foo") | ||
c.Assert(err, IsNil) | ||
|
||
_, err = w.Commit("foo\n", cm) | ||
c.Assert(err, IsNil) | ||
|
||
_, err = w.Move("foo", "bar") | ||
c.Assert(err, IsNil) | ||
|
||
hash, err := w.Commit("rename foo to bar", cm) | ||
c.Assert(err, IsNil) | ||
|
||
commit, err := r.CommitObject(hash) | ||
c.Assert(err, IsNil) | ||
|
||
fileStats, err := commit.Stats() | ||
c.Assert(err, IsNil) | ||
c.Assert(fileStats[0].Name, Equals, "foo => bar") | ||
} |