Commit 90fe58b6 authored by borenet@google.com's avatar borenet@google.com

gclient_scm: Only _DeleteOrMove if _Clone fails

BUG=

Review URL: https://codereview.chromium.org/262813002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@267587 0039d316-1c4b-4281-b951-d872f2087c98
parent f75c230c
......@@ -352,14 +352,11 @@ class GitWrapper(SCMWrapper):
if (not os.path.exists(self.checkout_path) or
(os.path.isdir(self.checkout_path) and
not os.path.exists(os.path.join(self.checkout_path, '.git')))):
if (os.path.isdir(self.checkout_path) and
not os.path.exists(os.path.join(self.checkout_path, '.git')) and
os.listdir(self.checkout_path)):
# This is a little hack to work around checkouts which are created
# using "gclient config --name ."
if not self.relpath == '.':
self._DeleteOrMove(options.force)
self._Clone(revision, url, options)
try:
self._Clone(revision, url, options)
except subprocess2.CalledProcessError:
self._DeleteOrMove(options.force)
self._Clone(revision, url, options)
self._UpdateBranchHeads(options, fetch=True)
if file_list is not None:
files = self._Capture(['ls-files']).splitlines()
......
......@@ -1297,11 +1297,6 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase):
gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
).AndReturn(False)
gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
).AndReturn(False)
self.mox.StubOutWithMock(gclient_scm.os, 'listdir', True)
gclient_scm.os.listdir(self.base_path).AndReturn([])
self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
# pylint: disable=E1120
......@@ -1324,23 +1319,24 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase):
scm.update(options, None, [])
self.checkstdout('\n')
def testUpdateNoDotGitForce(self):
options = self.Options(force=True)
def testUpdateConflict(self):
options = self.Options()
gclient_scm.os.path.exists(self.base_path).AndReturn(True)
gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
).AndReturn(False)
gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
).AndReturn(False)
self.mox.StubOutWithMock(gclient_scm.os, 'listdir', True)
gclient_scm.os.listdir(self.base_path).AndReturn([])
self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
# pylint: disable=E1120
gclient_scm.GitWrapper._Clone(
'refs/remotes/origin/master', self.url, options
).AndRaise(gclient_scm.subprocess2.CalledProcessError(None, None, None,
None, None))
self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_DeleteOrMove', True)
gclient_scm.GitWrapper._DeleteOrMove(False)
gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
options)
# pylint: disable=E1120
self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
gclient_scm.subprocess2.check_output(
['git', 'ls-files'], cwd=self.base_path,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment