Enhance 'rbt patch' for better merging and feedback.
Review Request #6236 — Created Aug. 16, 2014 and submitted — Latest diff uploaded
By default,
git apply
isn't very good at handling patches that don't
apply perfectly cleanly. It will just fail with an error. That means if
you attempt to apply a patch, and the underlying files have changed,
even just a little, nothing will be applied, and the user will be shown
an error.
git apply
has a nice option we can use to force better behavior:
-3
(or--3way
). This enables Git's merge behavior for patches, and will
also generate conflict markers. This option implies--index
, so that has
been removed from the command line.When a patch does fail to apply, partially or fully, it no longer shows
an "Unable to execute command" error. Instead,apply_patch()
returns a
PatchResult
, which contains the state of the patch operation, including
any list of conflicting files that could be reported, and any output
from the patch command line.This is then shown to the user. The output shows that the patch is being
applied, then shows the patch output, and then the status as a
human-readable message. If any conflicting files were seen (Git only,
for now), those will be shown as well.
Tested with both Git and Mercurial, in all failure/success modes.
For Git, I tested with and without a list of conflicting files.