Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bec6157

Browse filesBrowse files
authored
Merge pull request gitpython-developers#1485 from thehale/blame/rev-opts
feat(blame): Support custom `rev_opts` for blame
2 parents 73bde1f + 18a79d8 commit bec6157
Copy full SHA for bec6157

3 files changed

+16-3Lines changed: 16 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎AUTHORS‎

Copy file name to clipboardExpand all lines: AUTHORS
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ Contributors are:
4949
-Julien Mauroy <pro.julien.mauroy _at_ gmail.com>
5050
-Patrick Gerard
5151
-Luke Twist <itsluketwist@gmail.com>
52+
-Joseph Hale <me _at_ jhale.dev>
5253
Portions derived from other open source works and are clearly marked.
Collapse file

‎git/repo/base.py‎

Copy file name to clipboardExpand all lines: git/repo/base.py
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,12 @@ def blame_incremental(self, rev: str | HEAD, file: str, **kwargs: Any) -> Iterat
950950
)
951951

952952
def blame(
953-
self, rev: Union[str, HEAD], file: str, incremental: bool = False, **kwargs: Any
953+
self,
954+
rev: Union[str, HEAD],
955+
file: str,
956+
incremental: bool = False,
957+
rev_opts: Optional[List[str]] = None,
958+
**kwargs: Any
954959
) -> List[List[Commit | List[str | bytes] | None]] | Iterator[BlameEntry] | None:
955960
"""The blame information for the given file at the given revision.
956961
@@ -962,8 +967,8 @@ def blame(
962967
of appearance."""
963968
if incremental:
964969
return self.blame_incremental(rev, file, **kwargs)
965-
966-
data: bytes = self.git.blame(rev, "--", file, p=True, stdout_as_string=False, **kwargs)
970+
rev_opts = rev_opts or []
971+
data: bytes = self.git.blame(rev, *rev_opts, "--", file, p=True, stdout_as_string=False, **kwargs)
967972
commits: Dict[str, Commit] = {}
968973
blames: List[List[Commit | List[str | bytes] | None]] = []
969974

Collapse file

‎test/test_repo.py‎

Copy file name to clipboardExpand all lines: test/test_repo.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,13 @@ def test_blame_complex_revision(self, git):
553553
self.assertEqual(len(res), 1)
554554
self.assertEqual(len(res[0][1]), 83, "Unexpected amount of parsed blame lines")
555555

556+
@mock.patch.object(Git, "_call_process")
557+
def test_blame_accepts_rev_opts(self, git):
558+
res = self.rorepo.blame("HEAD", "README.md", rev_opts=["-M", "-C", "-C"])
559+
expected_args = ['blame', 'HEAD', '-M', '-C', '-C', '--', 'README.md']
560+
boilerplate_kwargs = {"p" : True, "stdout_as_string": False}
561+
git.assert_called_once_with(*expected_args, **boilerplate_kwargs)
562+
556563
@skipIf(
557564
HIDE_WINDOWS_KNOWN_ERRORS and Git.is_cygwin(),
558565
"""FIXME: File "C:\\projects\\gitpython\\git\\cmd.py", line 671, in execute

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.