0

In ObjectiveGit (which is an objective c wrapper of libgit2), when I have a file conflict that is not automatically resolved (this usually means that I have a local commit and remote commit that both changed the same line of a file), then I can enumerate the conflicted file using the built in method -[GTIndex enumerateConflictedFilesWithError:usingBlock:]. However, once I know of the conflicted file I can't figure out how to resolve it. Even if I chose to hardcode to preserve the OUR version, rather than the THEIR version, when I add it to the index using -[GTIndex addEntry:error:] nothing appears to change in the repo and the conflict still exists. I have found that using -[GTIndex addFile:error:] and passing the path associated with the OUR value adds the file and resolves the conflict, but it adds the file with GIT annotations such as <<<<<<<<< HEAD that preserve the local and remote changes. These break the file.

Does anyone know how I can resolve the conflict?

The file and line in question are here: https://github.com/jeffreybergier/Hipstapaper/blob/cf1c81cdf38871ad1f5d926faeb9ea64e992f22e/Hipstapaper/Sync_shared/SyncDirectory.swift#L47

and here (same file, different line): https://github.com/jeffreybergier/Hipstapaper/blob/cf1c81cdf38871ad1f5d926faeb9ea64e992f22e/Hipstapaper/Sync_shared/SyncDirectory.swift#L102

Jeffrey Bergier
  • 229
  • 1
  • 8
  • It looks like, according to this comment on the libgit project that its not possible to "choose" one or the other side. https://github.com/libgit2/libgit2/issues/3940#issuecomment-250447791 It seems when the merge happens, the file gets merged with annotations no matter what. So I changed what I did, now I'm using regex to edit the file the way I want and then adding the file and committing the changes. This appears to solve the problem. – Jeffrey Bergier Aug 24 '18 at 22:47
  • 1
    When you have a conflict, libgit2 (and thus, ObjectiveGit) puts the conflicted file in the working directory and sets the index to a conflicted state. To resolve this, you need to put the contents you _want_ in the working directory and then add _that_ to the index. If what you want is one of the sides (the ours or theirs side) then you'll need to place that on disk explicitly. – Edward Thomson Aug 24 '18 at 23:29
  • 1
    I was just looking at the checkout documentation, and noticed there's `GIT_CHECKOUT_USE_OURS/THEIRS`, so maybe you can skip the whole merge markers that way ? – tiennou Oct 28 '18 at 14:18
  • 1
    @tiennou thanks for this comment. This is a really good lead! I'll have to check_it_out (sorry for the bad pun) – Jeffrey Bergier Oct 30 '18 at 18:31

0 Answers0