Skip to content

[RFC] Repository: get all values from git_merge_file_from_index #1376

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 19 additions & 5 deletions pygit2/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,15 @@ def merge_file_from_index(
ancestor: typing.Union[None, IndexEntry],
ours: typing.Union[None, IndexEntry],
theirs: typing.Union[None, IndexEntry],
) -> str:
"""Merge files from index. Return a string with the merge result
containing possible conflicts.
return_full: bool = False,
) -> typing.Union[str, tuple[bool, str, int, typing.Union[str, None]]]:
"""Merge files from index.

Returns: A string with the content of the file containing
possible conflicts.
If return_full then it returns a tuple containing
whether the file is automergeable, the content of the file,
the filemode and the path.

ancestor
The index entry which will be used as a common
Expand All @@ -693,6 +699,8 @@ def merge_file_from_index(
The index entry to take as "ours" or base.
theirs
The index entry which will be merged into "ours"
return_full
Whether to return the full output of the low-level call.
"""
cmergeresult = ffi.new('git_merge_file_result *')

Expand All @@ -709,10 +717,16 @@ def merge_file_from_index(
)
check_error(err)

ret = ffi.string(cmergeresult.ptr, cmergeresult.len).decode('utf-8')
automergeable = cmergeresult.automergeable != 0
content = ffi.string(cmergeresult.ptr, cmergeresult.len).decode('utf-8')
filemode = cmergeresult.mode
path = cmergeresult.path
C.git_merge_file_result_free(cmergeresult)

return ret
if not return_full:
return content
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a deprecation warning?


return automergeable, content, filemode, path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you return a smarter object, like a dataclass? With the name MergeFileResult, and using "contents" instead of "content" (as is written in the libgit2 reference documentation).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep... will do both things. Thanks for the feedback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests too please. Thanks!


def merge_commits(
self,
Expand Down