aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-12-01 09:52:22 +0000
committerGitHub <noreply@github.com>2023-12-01 09:52:22 +0000
commit4f614891047bae5d0f7a253f014175505b9821d7 (patch)
tree893cb82bc096539570f41f92cba57b66372a3565 /plumbing
parentae552ce0bf32cddb689727c4c9fa6bf4d3bd6499 (diff)
parentaebf868d2a557384539cf91476d21901ab378643 (diff)
downloadgo-git-4f614891047bae5d0f7a253f014175505b9821d7.tar.gz
Merge pull request #941 from djmoch/filestats-rename
plumbing: object, enable renames in getFileStatsFromFilePatches
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/object/patch.go4
-rw-r--r--plumbing/object/patch_stats_test.go54
2 files changed, 56 insertions, 2 deletions
diff --git a/plumbing/object/patch.go b/plumbing/object/patch.go
index 06bc35b..dd8fef4 100644
--- a/plumbing/object/patch.go
+++ b/plumbing/object/patch.go
@@ -317,8 +317,8 @@ func getFileStatsFromFilePatches(filePatches []fdiff.FilePatch) FileStats {
// File is deleted.
cs.Name = from.Path()
} else if from.Path() != to.Path() {
- // File is renamed. Not supported.
- // cs.Name = fmt.Sprintf("%s => %s", from.Path(), to.Path())
+ // File is renamed.
+ cs.Name = fmt.Sprintf("%s => %s", from.Path(), to.Path())
} else {
cs.Name = from.Path()
}
diff --git a/plumbing/object/patch_stats_test.go b/plumbing/object/patch_stats_test.go
new file mode 100644
index 0000000..f393c30
--- /dev/null
+++ b/plumbing/object/patch_stats_test.go
@@ -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: "foo@example.local", 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")
+}