1

I am using Objective-Git. I cannot get the following method to work:

- (GTIndex *)merge:(GTTree *)otherTree ancestor:(GTTree *)ancestorTree error:(NSError **)error

No error is returned, but the index returned is empty, while it exists, all attributes are nil. The merge operation does not take place, I can't write out a tree as I cannot obtain the index resulting from the attempted merge.

Has anybody managed to successfully perform a merge using objective git - How? Help!

        GTBranch *branch1 = branches[0];
        GTCommit *commit1 = [branch1 targetCommitAndReturnError:NULL];
        GTOID *oid1 =  commit1.OID;
        GTTree *tree1 = commit1.tree;

        GTBranch *branch2 = branches[1];
        GTCommit *commit2 = [branch2 targetCommitAndReturnError:NULL];
        GTTree *tree2 = commit2.tree;
        GTOID *oid2 =  commit2.OID;

        GTRepository *repo = branch1.repository;

        NSError *error;
        GTCommit *ancestor = [repo mergeBaseBetweenFirstOID:oid1 secondOID:oid2 error:&error];
        if (error){
            NSLog(@"%@", error.description);
        }
        GTTree *ancTree = ancestor.tree;
        NSError *someError;
        NSLog(@"attempting merge into ""%@"" from ""%@"" with ancestor ""%@""", commit2.message, commit1.message,ancestor.message);
        GTIndex *mergedIndex = [tree2 merge:tree1 ancestor: ancTree error:&someError];  //returns index not backed by existing repo --> index_file_path = nil,  all attributes of git_index are nil
        if (someError){
            NSLog(@"%@", someError.description);
        }
        NSError *theError;
        GTTree *mergedtree = [mergedIndex writeTree:&theError]; //can't write out the tree as the index given back by merge: ancestor: error: does not reference a repo
        if (theError){
            NSLog(@"%@",theError);
        }
    }
}
Kara
  • 6,115
  • 16
  • 50
  • 57
Coxy1989
  • 160
  • 1
  • 6

1 Answers1

5

The index that is returned by merging the trees together is not bound to the repository. Unfortunately, the operation to write the index as a tree to a specific repository (git_index_write_tree_to) is not exposed yet through Objective-Git.

You probably want to open a ticket in their issue tracker.

  • 2
    Indeed! You could also swap in the new index to your repository's index, but that's probably not advised unless you are very careful to ensure that you have no uncommitted tracked changes in the index to begin with. (Much better to merge the two indexes and put the result as the new repository index.) – Edward Thomson Jan 08 '14 at 22:06
  • Thank you for you answers. I've added the ticket Arthur. @Edward, is that possible without dropping down to libgit2? – Coxy1989 Jan 09 '14 at 00:39