Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGit2 Implementing 'git pull'

Tags:

git

libgit2

I have choose the following algorythm of pull:

  1. fetch()
  2. get current head commit
  3. get all not merged commits (realisation taken from here: How can I check if pull is needed using libgit2 in c++?)
  4. get first not merged commit (it is newest) from step 3.
  5. merge commits. From LastFetchedCommit (step 4) into headCommit (step 2).

1-4 works perfectly

I have a problems with 5:

git_merge_commits(&rezPointer, repo.pointer , commitFrom.pointer, commitInto.pointer, &mrgOptions)

I'm trying to pull remote repo that have 2 additional commits relatively to local repo.

error:

Error Domain=lib.git_index_write_tree failed: Failed to write tree. the index file is not backed up by an existing repository Code=-1 "Failed to write tree. the index file is not backed up by an existing repository" UserInfo={NSLocalizedDescription=Failed to write tree. the index file is not backed up by an existing repository, NSLocalizedFailureReason=git_index_write_tree failed.}

do I did something wrong?

like image 940
Andrew Avatar asked Oct 17 '25 23:10

Andrew


1 Answers

That could be as described in issue 2668

If I call git_index_write_tree(), it fails with Failed to write tree. The index file is not backed up by an existing repository.

That's what git_index_write_tree_to() is for.

But it's not about bare vs non-bare, it's about whether you asked the repository for an index or if you created one without any associations.

A bit like in issue 5015, where a reference to the index is explicitly set, and used (without error message):

    git_repository *src, *dst;                                                                                         
    git_index *index;
    git_oid id;
    
    git_libgit2_init();                                                                                                
    
    err = git_repository_open(&src, "src");                                                                            
    err = git_repository_open(&dst, "dst");
    err = git_repository_index(&index, src);

    err = git_index_write_tree_to(&id, index, dst);
like image 183
VonC Avatar answered Oct 19 '25 13:10

VonC