Improve patch handling and tests.
R=dpranke@chromium.org
BUG=
TEST=
Review URL: http://codereview.chromium.org/6877038
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@82406 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/patch.py b/patch.py
index f6b19ac..316333f 100644
--- a/patch.py
+++ b/patch.py
@@ -246,8 +246,14 @@
match = re.match(r'^--- ([^\t]+).*$', lines.pop(0))
if not match:
continue
- if match.group(1) not in (self.filename, '/dev/null'):
- self._fail('Unexpected diff: %s.' % match.group(1))
+ # For copy and renames, it's possible that the -- line doesn't match +++,
+ # so don't check match.group(1) to match self.filename or '/dev/null', it
+ # can be anything else.
+ # TODO(maruel): Handle rename/copy explicitly.
+ # if match.group(1) not in (self.filename, '/dev/null'):
+ # self.source_file = match.group(1)
+ if not lines:
+ self._fail('Nothing after header.')
match = re.match(r'^\+\+\+ ([^\t]+).*$', lines.pop(0))
if not match:
self._fail('Unexpected diff: --- not following +++.')