From fb176482f3a1f8019db810f5a9f564676e512da1 Mon Sep 17 00:00:00 2001 From: "tony@chromium.org" Date: Fri, 4 Jun 2010 00:49:49 +0000 Subject: [PATCH] When running an svn update, if --force was passed on the command line to gclient, pass the flag to svn update and svn co too. This allows updates when we have dirty files left around. For example, an update may remove a directory, but the directory still has .vcproj or .mk files in it. If we try to re-add that directory, svn will error out. If we add --force, it'll happily allow the update. Review URL: http://codereview.chromium.org/2560001 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@48897 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient_scm.py | 24 ++++++++++++++++-------- tests/gclient_scm_test.py | 4 +++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gclient_scm.py b/gclient_scm.py index 134df35b02..1fe263c256 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -740,8 +740,7 @@ class SVNWrapper(SCMWrapper): if not os.path.exists(checkout_path): # We need to checkout. command = ['checkout', url, checkout_path] - if revision: - command.extend(['--revision', str(revision).strip()]) + command = self.AddAdditionalFlags(command, options, revision) scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) return @@ -798,8 +797,7 @@ class SVNWrapper(SCMWrapper): gclient_utils.RemoveDirectory(checkout_path) # We need to checkout. command = ['checkout', url, checkout_path] - if revision: - command.extend(['--revision', str(revision).strip()]) + command = self.AddAdditionalFlags(command, options, revision) scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) return @@ -812,8 +810,7 @@ class SVNWrapper(SCMWrapper): return command = ["update", checkout_path] - if revision: - command.extend(['--revision', str(revision).strip()]) + command = self.AddAdditionalFlags(command, options, revision) scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) def updatesingle(self, options, args, file_list): @@ -841,8 +838,7 @@ class SVNWrapper(SCMWrapper): os.makedirs(checkout_path) command = ["export", os.path.join(self.url, filename), os.path.join(checkout_path, filename)] - if options.revision: - command.extend(['--revision', str(options.revision).strip()]) + command = self.AddAdditionalFlags(command, options, options.revision) scm.SVN.Run(command, self._root_dir) def revert(self, options, args, file_list): @@ -927,3 +923,15 @@ class SVNWrapper(SCMWrapper): def FullUrlForRelativeUrl(self, url): # Find the forth '/' and strip from there. A bit hackish. return '/'.join(self.url.split('/')[:4]) + url + + def AddAdditionalFlags(self, command, options, revision): + """Add additional flags to command depending on what options are set. + command should be a list of strings that represents an svn command. + + This method returns a new list to be used as a command.""" + new_command = command[:] + if revision: + new_command.extend(['--revision', str(revision).strip()]) + if options.force: + new_command.append('--force') + return new_command diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 175f8e9a32..a3302edaed 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -68,7 +68,7 @@ class SVNWrapperTestCase(BaseTestCase): def testDir(self): members = [ - 'FullUrlForRelativeUrl', 'RunCommand', + 'AddAdditionalFlags', 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'updatesingle', 'url', @@ -266,6 +266,8 @@ class SVNWrapperTestCase(BaseTestCase): additional_args = [] if options.manually_grab_svn_rev: additional_args = ['--revision', str(file_info['Revision'])] + if options.force: + additional_args.append('--force') files_list = [] gclient_scm.scm.SVN.RunAndGetFileList( options,