Skip to content

Repository.merge_file_from_index - can't take a None as an argument #1378

Description

@eantoranz

This is probably more of a libgit2 question but given that I am working on pygit2, I better start the conversation over here.

I am working on writing unit tests for Repository.merge_file_from_index. I want to add a test for a deleted file. The signature of the method provides for None as a valid argument:

    def merge_file_from_index(
        self,
        ancestor: typing.Union[None, IndexEntry],
        ours: typing.Union[None, IndexEntry],
        theirs: typing.Union[None, IndexEntry],
    ) -> str:

So I have this:

def test_merge_file_from_index(testrepo):
    hello_txt = testrepo.index["hello.txt"]

    # deleting the file on theirs
    res = testrepo.merge_file_from_index(hello_txt, hello_txt, None)
    assert res == ""

And I am getting this when I run the test:

>       raise GitError(message)
E       _pygit2.GitError: invalid argument: 'theirs'

Am I wrong in my understanding from the signature that None is a correct value?

Activity

  1. eantoranz commented on Jun 13, 2025

    @eantoranz
    ContributorAuthor

    I guess the problem is coming from here in libgit2

    int git_merge_file_from_index(
    	git_merge_file_result *out,
    	git_repository *repo,
    	const git_index_entry *ancestor,
    	const git_index_entry *ours,
    	const git_index_entry *theirs,
    	const git_merge_file_options *options)
    {
    	git_merge_file_input *ancestor_ptr = NULL,
    		ancestor_input = {0}, our_input = {0}, their_input = {0};
    	git_odb *odb = NULL;
    	git_odb_object *odb_object[3] = { 0 };
    	int error = 0;
    
    	GIT_ASSERT_ARG(out);
    	GIT_ASSERT_ARG(repo);
    	GIT_ASSERT_ARG(ours);
    	GIT_ASSERT_ARG(theirs); // <- HERE.... same problem with ours
    
  2. eantoranz commented on Jun 14, 2025

    @eantoranz
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions