From a9d9aa429f907482b9875da5ca7a01deef9635d5 Mon Sep 17 00:00:00 2001 From: "borenet@google.com" Date: Tue, 22 Apr 2014 17:42:54 +0000 Subject: [PATCH] gclient: Only _DeleteOrMove if the destination directory is non-empty BUG=364601 Review URL: https://codereview.chromium.org/246433005 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@265298 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient_scm.py | 3 ++- tests/gclient_scm_test.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gclient_scm.py b/gclient_scm.py index 89647ac0e..b5a09a224 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -352,7 +352,8 @@ class GitWrapper(SCMWrapper): (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'))): + 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 == '.': diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index c49b5247e..dbd94f0a7 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -1300,6 +1300,8 @@ 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) + 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 @@ -1332,6 +1334,8 @@ 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) + 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,