diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2023-01-14 08:21:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 08:21:54 +0100 |
commit | 3901d4ccdbd7c2450ff6faadebf2d33e2b246a7b (patch) | |
tree | 737b3b357d7ec4e91508ef2890eb817f4483e9be | |
parent | 90c81a56dffe77fc08f863769d35762ca66240b0 (diff) | |
parent | c9b44d29d656e92bb08fa41bcc2c31b2a2a2607b (diff) | |
download | gitpython-3901d4ccdbd7c2450ff6faadebf2d33e2b246a7b.tar.gz |
Merge pull request #1537 from teknoraver/main
fix files list on file rename
-rw-r--r-- | git/objects/commit.py | 4 | ||||
-rw-r--r-- | test/test_commit.py | 31 |
2 files changed, 33 insertions, 2 deletions
diff --git a/git/objects/commit.py b/git/objects/commit.py index 82d2387b..547e8fe8 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -324,14 +324,14 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable): :return: git.Stats""" if not self.parents: - text = self.repo.git.diff_tree(self.hexsha, "--", numstat=True, root=True) + text = self.repo.git.diff_tree(self.hexsha, "--", numstat=True, no_renames=True, root=True) text2 = "" for line in text.splitlines()[1:]: (insertions, deletions, filename) = line.split("\t") text2 += "%s\t%s\t%s\n" % (insertions, deletions, filename) text = text2 else: - text = self.repo.git.diff(self.parents[0].hexsha, self.hexsha, "--", numstat=True) + text = self.repo.git.diff(self.parents[0].hexsha, self.hexsha, "--", numstat=True, no_renames=True) return Stats._list_from_string(self.repo, text) @property diff --git a/test/test_commit.py b/test/test_commit.py index c5a43c94..1efc6889 100644 --- a/test/test_commit.py +++ b/test/test_commit.py @@ -159,6 +159,37 @@ class TestCommit(TestCommitSerialization): self.assertEqual(commit.committer_tz_offset, 14400, commit.committer_tz_offset) self.assertEqual(commit.message, "initial project\n") + def test_renames(self): + commit = self.rorepo.commit("185d847ec7647fd2642a82d9205fb3d07ea71715") + files = commit.stats.files + + # when a file is renamed, the output of git diff is like "dir/{old => new}" + # unless we disable rename with --no-renames, which produces two lines + # one with the old path deletes and another with the new added + self.assertEqual(len(files), 2) + + def check_entries(path, changes): + expected = { + ".github/workflows/Future.yml" : { + 'insertions': 57, + 'deletions': 0, + 'lines': 57 + }, + ".github/workflows/test_pytest.yml" : { + 'insertions': 0, + 'deletions': 55, + 'lines': 55 + }, + } + assert path in expected + assert isinstance(changes, dict) + for key in ("insertions", "deletions", "lines"): + assert changes[key] == expected[path][key] + + for path, changes in files.items(): + check_entries(path, changes) + # END for each stated file + def test_unicode_actor(self): # assure we can parse unicode actors correctly name = "Üäöß ÄußÉ" |