Fix handling of file renames.
The patches needs to by applied 'in-order' to not delete source files.
Added more tests.
[email protected]
BUG=94330
TEST=
Review URL: http://codereview.chromium.org/8038056
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@103309 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tests/checkout_test.py b/tests/checkout_test.py
index 21cd671..1428bd7 100755
--- a/tests/checkout_test.py
+++ b/tests/checkout_test.py
@@ -40,6 +40,11 @@
'--non-interactive', '--no-auth-cache',
'--username', self.USERS[0][0], '--password', self.USERS[0][1]])
assert os.path.isdir(os.path.join(self.svn_checkout, '.svn'))
+ self._commit_svn(self._tree_1())
+ self._commit_svn(self._tree_2())
+
+ @staticmethod
+ def _tree_1():
fs = {}
fs['trunk/origin'] = 'svn@1'
fs['trunk/codereview.settings'] = (
@@ -63,11 +68,26 @@
'ooo\n'
'pp\n'
'q\n')
- self._commit_svn(fs)
+ return fs
+
+ @classmethod
+ def _tree_2(cls):
+ fs = cls._tree_1()
fs['trunk/origin'] = 'svn@2\n'
fs['trunk/extra'] = 'dummy\n'
fs['trunk/bin_file'] = '\x00'
- self._commit_svn(fs)
+ fs['trunk/chromeos/views/DOMui_menu_widget.h'] = (
+ '// Copyright (c) 2010\n'
+ '// Use of this source code\n'
+ '// found in the LICENSE file.\n'
+ '\n'
+ '#ifndef DOM\n'
+ '#define DOM\n'
+ '#pragma once\n'
+ '\n'
+ '#include <string>\n'
+ '#endif\n')
+ return fs
def populateGit(self):
raise NotImplementedError()
@@ -100,11 +120,10 @@
def get_patches(self):
return patch.PatchSet([
+ patch.FilePatchDiff('new_dir/subdir/new_file', GIT.NEW_SUBDIR, []),
+ patch.FilePatchDiff('chrome/file.cc', GIT.PATCH, []),
# TODO(maruel): Test with is_new == False.
patch.FilePatchBinary('bin_file', '\x00', [], is_new=True),
- patch.FilePatchDiff(
- 'chrome/file.cc', GIT.PATCH, []),
- patch.FilePatchDiff('new_dir/subdir/new_file', GIT.NEW_SUBDIR, []),
patch.FilePatchDelete('extra', False),
])
@@ -201,6 +220,35 @@
self.assertEquals(len(expected), len(results))
self.assertEquals(expected, results)
+ def _check_move(self, co):
+ """Makes sure file moves are handled correctly."""
+ co.prepare(None)
+ patchset = patch.PatchSet([
+ patch.FilePatchDelete('chromeos/views/DOMui_menu_widget.h', False),
+ patch.FilePatchDiff(
+ 'chromeos/views/webui_menu_widget.h', GIT.RENAME_PARTIAL, []),
+ ])
+ co.apply_patch(patchset)
+ # Make sure chromeos/views/DOMui_menu_widget.h is deleted and
+ # chromeos/views/webui_menu_widget.h is correctly created.
+ root = os.path.join(self.root_dir, self.name)
+ tree = self.get_trunk(False)
+ del tree['chromeos/views/DOMui_menu_widget.h']
+ tree['chromeos/views/webui_menu_widget.h'] = (
+ '// Copyright (c) 2011\n'
+ '// Use of this source code\n'
+ '// found in the LICENSE file.\n'
+ '\n'
+ '#ifndef WEB\n'
+ '#define WEB\n'
+ '#pragma once\n'
+ '\n'
+ '#include <string>\n'
+ '#endif\n')
+ #print patchset[0].get()
+ #print fake_repos.read_tree(root)
+ self.assertTree(tree, root)
+
class SvnBaseTest(BaseTest):
def setUp(self):
@@ -349,6 +397,9 @@
def testPrepare(self):
self._test_prepare(self._get_co(None))
+ def testMove(self):
+ self._check_move(self._get_co(None))
+
class GitSvnCheckout(SvnBaseTest):
name = 'foo.git'
@@ -419,6 +470,9 @@
co.prepare = prepare
self._test_prepare(co)
+ def testMove(self):
+ self._check_move(self._get_co(None))
+
class RawCheckout(SvnBaseTest):
def setUp(self):
@@ -482,6 +536,9 @@
self._test_prepare(co)
self.assertEquals([], revs)
+ def testMove(self):
+ self._check_move(self._get_co(None))
+
class ReadOnlyCheckout(SvnBaseTest):
# Use SvnCheckout as the backed since it support read-only checkouts too.
@@ -513,6 +570,9 @@
def testPrepare(self):
self._test_prepare(self._get_co(None))
+ def testMove(self):
+ self._check_move(self._get_co(None))
+
if __name__ == '__main__':
if '-v' in sys.argv: