diff --git a/patch.py b/patch.py index 4c96de356..4a67cadfc 100644 --- a/patch.py +++ b/patch.py @@ -289,7 +289,13 @@ class FilePatchDiff(FilePatchBase): (match.group(1), line)) return - # Ignore "deleted file mode 100644" since it's not needed. + match = re.match(r'^deleted file mode (\d{6})$', line) + if match: + # It is necessary to parse it because there may be no hunk, like when the + # file was empty. + self.is_delete = True + return + match = re.match(r'^new(| file) mode (\d{6})$', line) if match: mode = match.group(2) @@ -297,6 +303,7 @@ class FilePatchDiff(FilePatchBase): # TODO(maruel): Add support to remove a property. if bool(int(mode[4]) & 1): self.svn_properties.append(('svn:executable', '*')) + return match = re.match(r'^--- (.*)$', line) if match: diff --git a/testing_support/patches_data.py b/testing_support/patches_data.py index eac2fed48..b70f55ba3 100644 --- a/testing_support/patches_data.py +++ b/testing_support/patches_data.py @@ -98,6 +98,14 @@ class GIT(object): '-Also see\n' '\n') + # http://codereview.chromium.org/download/issue8508015_6001_7001.diff + DELETE_EMPTY = ( + 'Index: tests/__init__.py\n' + 'diff --git a/tests/__init__.py b/tests/__init__.py\n' + 'deleted file mode 100644\n' + 'index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..' + '0000000000000000000000000000000000000000\n') + # http://codereview.chromium.org/download/issue6250123_3013_6010.diff RENAME_PARTIAL = ( 'Index: chromeos/views/webui_menu_widget.h\n' diff --git a/tests/rietveld_test.py b/tests/rietveld_test.py index 5f6bb0480..fa13945e9 100755 --- a/tests/rietveld_test.py +++ b/tests/rietveld_test.py @@ -188,7 +188,23 @@ class RietveldTest(unittest.TestCase): ] patches = self.rietveld.get_patch(123, 456) self.assertEquals(1, len(patches.patches)) - self._check_patch(patches.patches[0], name, None, is_delete=True) + self._check_patch(patches.patches[0], name, RAW.DELETE, is_delete=True) + + def test_delete_empty(self): + name = 'tests/__init__.py' + self.requests = [ + ('/api/123/456', _api({name: _file('D')})), + ('/download/issue123_456_789.diff', GIT.DELETE_EMPTY), + ] + patches = self.rietveld.get_patch(123, 456) + self.assertEquals(1, len(patches.patches)) + self._check_patch( + patches.patches[0], + name, + GIT.DELETE_EMPTY, + is_delete=True, + is_git_diff=True, + patchlevel=1) def test_m_plus(self): properties = '\nAdded: svn:eol-style\n + LF\n' @@ -348,5 +364,6 @@ class RietveldTest(unittest.TestCase): if __name__ == '__main__': - logging.basicConfig(level=logging.ERROR) + logging.basicConfig(level=[ + logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))]) unittest.main()