FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

diff: Add option to specify lines of context to diff function · gitpython-developers/GitPython@29041f2 · GitHub

Repository navigation

Commit 29041f2

Browse files
Ben Totten
committed
diff: Add option to specify lines of context to diff function
1 parent 64ec0b1 commit 29041f2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎git/diff.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def diff(
185185
other: Union[DiffConstants, "Tree", "Commit", str, None] = INDEX,
186186
paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None,
187187
create_patch: bool = False,
188+
lines_of_context: int = 3,
188189
**kwargs: Any,
189190
) -> "DiffIndex":
190191
"""Create diffs between two items being trees, trees and index or an index and
@@ -214,6 +215,10 @@ def diff(
214215
applied makes the self to other. Patches are somewhat costly as blobs have
215216
to be read and diffed.
216217
218+
:param line_of_context:
219+
Default 3. Specify the lines of context before and after each change
220+
introduced in the patch. This cooresponds to the -U flag for git diff.
221+
217222
:param kwargs:
218223
Additional arguments passed to :manpage:`git-diff(1)`, such as ``R=True`` to
219224
swap both sides of the diff.
@@ -241,6 +246,9 @@ def diff(
241246
args.append("--raw")
242247
args.append("-z")
243248

249+
if lines_of_context:
250+
args.append(f"-U{lines_of_context}")
251+
244252
# Ensure we never see colored output.
245253
# Fixes: https://github.com/gitpython-developers/GitPython/issues/172
246254
args.append("--no-color")

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL