Revert of If the destination directory doesn't contain the desired repo, delete it (https://codereview.chromium.org/61623008/)
Reason for revert:
This breaks `gclient sync` for me. Before this patch:
________ found .git directory; skipping src
After this patch:
Error: 1> Can't update/checkout /Volumes/MacintoshHD2/src/chrome-git/src if an unversioned directory is present. Delete the directory and try again.
Original issue's description:
> If the destination directory doesn't contain the desired repo, delete it
>
> Basic functionality - this may not be in quite the right place.
>
> Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=245404
TBR=iannucci@chromium.org,ilevy@chromium.org,cmp@chromium.org,maruel@chromium.org,morrita@chromium.org,borenet@google.com
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.chromium.org/141633005
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@245530 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py
index 99007b0..5607f85 100755
--- a/tests/gclient_scm_test.py
+++ b/tests/gclient_scm_test.py
@@ -102,7 +102,6 @@
'BinaryExists',
'FullUrlForRelativeUrl',
'GetCheckoutRoot',
- 'GetRemoteURL',
'GetRevisionDate',
'GetUsableRev',
'Svnversion',
@@ -163,6 +162,8 @@
def testRunCommandException(self):
options = self.Options(verbose=False)
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
@@ -182,6 +183,8 @@
gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
).AndReturn('1.5.1')
# It'll to a checkout instead.
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
# Checkout.
gclient_scm.os.path.exists(self.base_path).AndReturn(False)
parent = gclient_scm.os.path.dirname(self.base_path)
@@ -209,7 +212,11 @@
options = self.Options(verbose=True, force=True)
gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False)
+ gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
# Checkout.
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
gclient_scm.os.path.exists(self.base_path).AndReturn(False)
parent = gclient_scm.os.path.dirname(self.base_path)
gclient_scm.os.path.exists(parent).AndReturn(False)
@@ -334,6 +341,8 @@
file_info.url = self.url
file_info.uuid = 'ABC'
file_info.revision = 42
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
# Checkout.
gclient_scm.os.path.exists(self.base_path).AndReturn(False)
parent = gclient_scm.os.path.dirname(self.base_path)
@@ -365,6 +374,8 @@
'UUID': 'ABC',
'Revision': 42,
}
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
gclient_scm.os.path.exists(self.base_path).AndReturn(True)
# Checkout or update.
@@ -409,6 +420,8 @@
'UUID': 'ABC',
'Revision': 42,
}
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
gclient_scm.os.path.exists(self.base_path).AndReturn(True)
# Checkout or update.
@@ -443,6 +456,8 @@
'UUID': 'ABC',
'Revision': 42,
}
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
gclient_scm.os.path.exists(self.base_path).AndReturn(True)
# Checkout or update.
@@ -507,6 +522,8 @@
file_list=files_list)
# Now we fall back on scm.update().
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
gclient_scm.os.path.exists(self.base_path).AndReturn(True)
gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
@@ -575,6 +592,8 @@
file_list=files_list)
# Now we fall back on scm.update().
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
gclient_scm.os.path.exists(self.base_path).AndReturn(True)
gclient_scm.scm.SVN._CaptureInfo(
[], join(self.base_path, ".")).AndReturn(file_info)
@@ -609,6 +628,8 @@
# Now we fall back on scm.update().
files_list = self.mox.CreateMockAnything()
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
gclient_scm.os.path.exists(self.base_path).AndReturn(True)
gclient_scm.scm.SVN._CaptureInfo(
[], join(self.base_path, '.')).AndReturn(file_info)
@@ -624,6 +645,32 @@
scm.updatesingle(options, ['DEPS'], files_list)
self.checkstdout('\n_____ %s at 42\n' % self.relpath)
+ def testUpdateGit(self):
+ options = self.Options(verbose=True)
+ file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
+ gclient_scm.os.path.exists(file_path).AndReturn(True)
+
+ self.mox.ReplayAll()
+ scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
+ relpath=self.relpath)
+ file_list = []
+ scm.update(options, self.args, file_list)
+ self.checkstdout(
+ ('________ found .git directory; skipping %s\n' % self.relpath))
+
+ def testUpdateHg(self):
+ options = self.Options(verbose=True)
+ gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
+ gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True)
+
+ self.mox.ReplayAll()
+ scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
+ relpath=self.relpath)
+ file_list = []
+ scm.update(options, self.args, file_list)
+ self.checkstdout(
+ ('________ found .hg directory; skipping %s\n' % self.relpath))
+
def testGetUsableRevSVN(self):
# pylint: disable=E1101
options = self.Options(verbose=True)
@@ -645,48 +692,6 @@
self.assertRaises(gclient_scm.gclient_utils.Error,
svn_scm.GetUsableRev, 'fake', options)
- def testGetRemoteURL(self):
- self.mox.UnsetStubs()
- options = self.Options(verbose=True)
- self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture', True)
- svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
- relpath=self.relpath)
-
- if svn_scm.relpath:
- cwd = os.path.join(svn_scm._root_dir, svn_scm.relpath)
- else:
- cwd = svn_scm._root_dir
-
- gclient_scm.scm.SVN.Capture(['info', '--xml', os.curdir], cwd).AndReturn(
-"""<?xml version="1.0"?>
-<info>
-<entry
- path="."
- revision="1234"
- kind="dir">
-<url>%s</url>
-<repository>
-<root>https://dummy.repo.com/svn</root>
-<uuid>FAKE</uuid>
-</repository>
-<wc-info>
-<schedule>normal</schedule>
-<depth>infinity</depth>
-</wc-info>
-<commit
- revision="1234">
-<author>fakedev@chromium.org</author>
-<date>2013-11-14T15:08:21.757885Z</date>
-</commit>
-</entry>
-</info>
-""" % svn_scm.url)
-
- self.mox.ReplayAll()
-
- self.assertEquals(svn_scm.GetRemoteURL(options), self.url)
-
-
class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils,
unittest.TestCase):
"""This class doesn't use pymox."""
@@ -812,7 +817,6 @@
'BinaryExists',
'FullUrlForRelativeUrl',
'GetCheckoutRoot',
- 'GetRemoteURL',
'GetRevisionDate',
'GetUsableRev',
'RunCommand',
@@ -1181,18 +1185,6 @@
self.assertRaises(gclient_scm.gclient_utils.Error,
git_svn_scm.GetUsableRev, too_big, options)
- def testGetRemoteURL(self):
- options = self.Options(verbose=True)
- self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Capture', True)
- git_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
- relpath=self.relpath)
- git_scm._Capture(['config', 'remote.origin.url'], cwd='/tmp/fake'
- ).AndReturn('%s\n' % git_scm.url)
-
- self.mox.ReplayAll()
-
- self.assertEquals(git_scm.GetRemoteURL(options), self.url)
-
class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
def testUpdateUpdate(self):