Skip to content

Pass blame flags to blame options object. #1083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pygit2/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ def blame(self, path, flags=None, min_match_characters=None,

options = ffi.new('git_blame_options *')
C.git_blame_init_options(options, C.GIT_BLAME_OPTIONS_VERSION)
if flags:
options.flags = flags
if min_match_characters:
options.min_match_characters = min_match_characters
if newest_commit:
Expand Down
6 changes: 6 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def barerepo_path(tmp_path):
yield pygit2.Repository(path), path


@pytest.fixture
def blameflagsrepo(tmp_path):
with utils.TemporaryRepository('blameflagsrepo.tar', tmp_path) as path:
yield pygit2.Repository(path)


@pytest.fixture
def dirtyrepo(tmp_path):
with utils.TemporaryRepository('dirtyrepo.tar', tmp_path) as path:
Expand Down
Binary file added test/data/blameflagsrepo.tar
Binary file not shown.
20 changes: 19 additions & 1 deletion test/test_blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import pytest

from pygit2 import Signature, Oid
from pygit2 import Signature, Oid, GIT_BLAME_IGNORE_WHITESPACE


PATH = 'hello.txt'
Expand Down Expand Up @@ -61,6 +61,24 @@ def test_blame_index(testrepo):
assert HUNKS[i][2] == hunk.orig_committer
assert HUNKS[i][3] == hunk.boundary


def test_blame_flags(blameflagsrepo):
blame = blameflagsrepo.blame(PATH, flags=GIT_BLAME_IGNORE_WHITESPACE)

assert len(blame) == 3

for i, hunk in enumerate(blame):
assert hunk.lines_in_hunk == 1
assert HUNKS[i][0] == hunk.final_commit_id
assert HUNKS[i][1] == hunk.final_start_line_number
assert HUNKS[i][2] == hunk.final_committer
assert HUNKS[i][0] == hunk.orig_commit_id
assert hunk.orig_path == PATH
assert HUNKS[i][1] == hunk.orig_start_line_number
assert HUNKS[i][2] == hunk.orig_committer
assert HUNKS[i][3] == hunk.boundary


def test_blame_with_invalid_index(testrepo):
blame = testrepo.blame(PATH)

Expand Down