Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit18a79d8

Browse files
committed
feat(blame): Support customrev_opts for blame
The `git blame` CLI offers a repeated `-C` option that can be used to detectlines that move within/between files. While a slower operation, it yields moreaccurate authorship reports.https://git-scm.com/docs/git-blame#Documentation/git-blame.txt--CltnumgtWhile GitPython does enable passing custom kwargs to the command line `git`invocation, the fact that kwargs is a dictionary (i.e. no duplicate keys) meansthat there was no way to request the `-C` option in `git blame` more than once.This commit adds an optional `rev_opts` parameter to the `blame` method whichaccepts a list of strings to propagate to the CLI invocation of `git blame`. Byusing a `List[str]` for `rev_opts`, users of GitPython can pass now the `-C`option multiple times to get more detailed authorship reports from `git blame`.
1 parent73bde1f commit18a79d8

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

‎AUTHORS

Lines 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.

‎git/repo/base.py

Lines 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
defblame(
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
ifincremental:
964969
returnself.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_optsor []
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

‎test/test_repo.py

Lines 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+
deftest_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_ERRORSandGit.is_cygwin(),
558565
"""FIXME: File "C:\\projects\\gitpython\\git\\cmd.py", line 671, in execute

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp