pygit2 merge simulating -Xtheirs or -Xours

91 Views Asked by At

I'm automating changing files in github using pygit2. Sometimes the files have changed in github while I am processing a repo so I want to pull() before I push().

Since this is automated I would like to avoid conflicts by either having my local changes always override the remote, or vice-versa. This seems like a very simple scenario but after hours of scouring the internet for examples I have found 0 examples of someone doing this. The pygit source itself has some examples that get close but the "handle conflicts" portion is just a "TODO" comment.

It looks like pygit2 should support it, but none of the APIs seem to do this.

For example,

Repository.merge_commits(ours, theirs, favor='normal', flags={}, file_flags={})

When I set favor="theirs" or favor="ours" and purposely force a conflict I still get conflicts.

I tried this:

ancestor_id = repo.merge_base(repo.head.target,remote_master_id)
repo.merge_trees(ancestor_id,repo.head,remote_master_id,favor="theirs")

No conflict now, but now I somehow end up with the repo in a state where both (ours and theirs) changes are in the commit history but the file itself is missing either change.

I'm just guessing here since I have no clue what merge_trees does (except "merge trees") and experimenting with values of ancestor_id.

Is there a way to get pygit2 to get it to do what I want?

0

There are 0 best solutions below