Commit b09097a4 authored by borenet@google.com's avatar borenet@google.com

gclient: print a warning if a dep would get deleted or moved in the future

BUG=skia:1638

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@262761 0039d316-1c4b-4281-b951-d872f2087c98
parent 848fd493
......@@ -194,6 +194,22 @@ class SCMWrapper(object):
# valid git or svn checkout.
return False
# TODO(borenet): Remove this once SCMWrapper._DeleteOrMove is enabled.
# pylint: disable=R0201
def _DeleteOrMove(self, force):
"""Delete the checkout directory or move it out of the way.
Args:
force: bool; if True, delete the directory. Otherwise, just move it.
"""
gclient_utils.AddWarning('WARNING: Upcoming change in '
'https://codereview.chromium.org/225403015 would '
'cause %s to be deleted or moved to the side. '
'This is intended to ease changes to DEPS in the '
'future. If you are seeing this warning and '
'haven\'t changed the DEPS file, please contact '
'borenet@ immediately.' % self.checkout_path)
class GitWrapper(SCMWrapper):
"""Wrapper for Git"""
......@@ -359,6 +375,9 @@ 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'))):
self._DeleteOrMove(options.force)
self._Clone(revision, url, options)
self._UpdateBranchHeads(options, fetch=True)
self.UpdateSubmoduleConfig()
......@@ -377,14 +396,6 @@ class GitWrapper(SCMWrapper):
self.Print('________ unmanaged solution; skipping %s' % self.relpath)
return self._Capture(['rev-parse', '--verify', 'HEAD'])
if not os.path.exists(os.path.join(self.checkout_path, '.git')):
raise gclient_utils.Error('\n____ %s%s\n'
'\tPath is not a git repo. No .git dir.\n'
'\tTo resolve:\n'
'\t\trm -rf %s\n'
'\tAnd run gclient sync again\n'
% (self.relpath, rev_str, self.relpath))
# See if the url has changed (the unittests use git://foo for the url, let
# that through).
current_url = self._Capture(['config', 'remote.%s.url' % self.remote])
......@@ -394,7 +405,7 @@ class GitWrapper(SCMWrapper):
# Skip url auto-correction if remote.origin.gclient-auto-fix-url is set.
# This allows devs to use experimental repos which have a different url
# but whose branch(s) are the same as official repos.
if (current_url != url and
if (current_url.rstrip('/') != url.rstrip('/') and
url != 'git://foo' and
subprocess2.capture(
['git', 'config', 'remote.%s.gclient-auto-fix-url' % self.remote],
......@@ -1064,12 +1075,7 @@ class SVNWrapper(SCMWrapper):
Raises:
Error: if can't get URL for relative path.
"""
# Only update if git or hg is not controlling the directory.
git_path = os.path.join(self.checkout_path, '.git')
if os.path.exists(git_path):
self.Print('________ found .git directory; skipping %s' % self.relpath)
return
# Only update if hg is not controlling the directory.
hg_path = os.path.join(self.checkout_path, '.hg')
if os.path.exists(hg_path):
self.Print('________ found .hg directory; skipping %s' % self.relpath)
......@@ -1100,21 +1106,26 @@ class SVNWrapper(SCMWrapper):
forced_revision = False
rev_str = ''
# Get the existing scm url and the revision number of the current checkout.
exists = os.path.exists(self.checkout_path)
if exists and managed:
# Git is only okay if it's a git-svn checkout of the right repo.
if scm.GIT.IsGitSvn(self.checkout_path):
remote_url = scm.GIT.Capture(['config', '--local', '--get',
'svn-remote.svn.url'],
cwd=self.checkout_path).rstrip()
if remote_url.rstrip('/') == base_url.rstrip('/'):
print('\n_____ %s looks like a git-svn checkout. Skipping.'
% self.relpath)
return # TODO(borenet): Get the svn revision number?
# Get the existing scm url and the revision number of the current checkout.
if exists and managed:
try:
from_info = scm.SVN.CaptureLocalInfo(
[], os.path.join(self.checkout_path, '.'))
except (gclient_utils.Error, subprocess2.CalledProcessError):
if options.reset and options.delete_unversioned_trees:
self.Print('Removing troublesome path %s' % self.checkout_path)
gclient_utils.rmtree(self.checkout_path)
exists = False
else:
msg = ('Can\'t update/checkout %s if an unversioned directory is '
'present. Delete the directory and try again.')
raise gclient_utils.Error(msg % self.checkout_path)
self._DeleteOrMove(options.force)
exists = False
BASE_URLS = {
'/chrome/trunk/src': 'gs://chromium-svn-checkout/chrome/',
......@@ -1194,7 +1205,9 @@ class SVNWrapper(SCMWrapper):
if not managed:
self.Print(('________ unmanaged solution; skipping %s' % self.relpath))
return self.Svnversion()
if os.path.exists(os.path.join(self.checkout_path, '.svn')):
return self.Svnversion()
return
if 'URL' not in from_info:
raise gclient_utils.Error(
......@@ -1238,7 +1251,7 @@ class SVNWrapper(SCMWrapper):
revision = str(from_info_live['Revision'])
rev_str = ' at %s' % revision
if from_info['URL'] != base_url:
if from_info['URL'].rstrip('/') != base_url.rstrip('/'):
# The repository url changed, need to switch.
try:
to_info = scm.SVN.CaptureRemoteInfo(url)
......
......@@ -171,7 +171,7 @@ class GIT(object):
@staticmethod
def IsGitSvn(cwd):
"""Returns true if this repo looks like it's using git-svn."""
"""Returns True if this repo looks like it's using git-svn."""
# If you have any "svn-remote.*" config keys, we think you're using svn.
try:
GIT.Capture(['config', '--local', '--get-regexp', r'^svn-remote\.'],
......
......@@ -752,6 +752,82 @@ class FakeRepoTransitive(FakeReposBase):
pass
class FakeRepoSkiaDEPS(FakeReposBase):
"""Simulates the Skia DEPS transition in Chrome."""
NB_GIT_REPOS = 5
DEPS_svn_pre = """deps = {
'src/third_party/skia/gyp': '%(svn_base)sskia/gyp',
'src/third_party/skia/include': '%(svn_base)sskia/include',
'src/third_party/skia/src': '%(svn_base)sskia/src',
}"""
DEPS_git_pre = """deps = {
'src/third_party/skia/gyp': '%(git_base)srepo_3',
'src/third_party/skia/include': '%(git_base)srepo_4',
'src/third_party/skia/src': '%(git_base)srepo_5',
}"""
DEPS_post = """deps = {
'src/third_party/skia': '%(git_base)srepo_1',
}"""
def populateSvn(self):
"""Create revisions which simulate the Skia DEPS transition in Chrome."""
subprocess2.check_call(
['svn', 'checkout', self.svn_base, self.svn_checkout,
'-q', '--non-interactive', '--no-auth-cache',
'--username', self.USERS[0][0], '--password', self.USERS[0][1]])
assert os.path.isdir(join(self.svn_checkout, '.svn'))
# Skia repo.
self._commit_svn({
'skia/skia_base_file': 'root-level file.',
'skia/gyp/gyp_file': 'file in the gyp directory',
'skia/include/include_file': 'file in the include directory',
'skia/src/src_file': 'file in the src directory',
})
# Chrome repo.
self._commit_svn({
'trunk/src/DEPS': self.DEPS_svn_pre % {'svn_base': self.svn_base},
'trunk/src/myfile': 'svn/trunk/src@1'
})
self._commit_svn({
'trunk/src/DEPS': self.DEPS_post % {'git_base': self.git_base},
'trunk/src/myfile': 'svn/trunk/src@2'
})
def populateGit(self):
# Skia repo.
self._commit_git('repo_1', {
'skia_base_file': 'root-level file.',
'gyp/gyp_file': 'file in the gyp directory',
'include/include_file': 'file in the include directory',
'src/src_file': 'file in the src directory',
})
self._commit_git('repo_3', { # skia/gyp
'gyp_file': 'file in the gyp directory',
})
self._commit_git('repo_4', { # skia/include
'include_file': 'file in the include directory',
})
self._commit_git('repo_5', { # skia/src
'src_file': 'file in the src directory',
})
# Chrome repo.
self._commit_git('repo_2', {
'DEPS': self.DEPS_git_pre % {'git_base': self.git_base},
'myfile': 'svn/trunk/src@1'
})
self._commit_git('repo_2', {
'DEPS': self.DEPS_post % {'git_base': self.git_base},
'myfile': 'svn/trunk/src@2'
})
class FakeReposTestBase(trial_dir.TestCase):
"""This is vaguely inspired by twisted."""
# Static FakeRepos instances. Lazy loaded.
......
This diff is collapsed.
......@@ -23,8 +23,6 @@ sys.path.insert(0, ROOT_DIR)
from testing_support.fake_repos import join, write
from testing_support.fake_repos import FakeReposTestBase, FakeRepoTransitive
import gclient_utils
import subprocess2
GCLIENT_PATH = os.path.join(ROOT_DIR, 'gclient')
......@@ -763,21 +761,6 @@ class GClientSmokeSVN(GClientSmokeBase):
self.checkBlock(res[0],
['running', 'running', 'running'])
def testUnversionedRepository(self):
# Check that gclient automatically deletes crippled SVN repositories.
if not self.enabled:
return
self.gclient(['config', self.svn_base + 'trunk/src/'])
cmd = ['sync', '--jobs', '1', '--delete_unversioned_trees', '--reset']
self.assertEquals(0, self.gclient(cmd)[-1])
third_party = join(self.root_dir, 'src', 'third_party')
subprocess2.check_call(['svn', 'propset', '-q', 'svn:ignore', 'foo', '.'],
cwd=third_party)
# Cripple src/third_party/foo and make sure gclient still succeeds.
gclient_utils.rmtree(join(third_party, 'foo', '.svn'))
self.assertEquals(0, self.gclient(cmd)[-1])
class GClientSmokeSVNTransitive(GClientSmokeBase):
FAKE_REPOS_CLASS = FakeRepoTransitive
......
......@@ -172,6 +172,18 @@ class RealGitSvnTest(fake_repos.FakeReposTestBase):
self._capture(['reset', '--hard', 'HEAD^'])
self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 1)
def testIsGitSvn(self):
if not self.enabled:
return
# Git-svn
self.assertTrue(scm.GIT.IsGitSvn(self.clone_dir))
# Pure git
git_dir = scm.os.path.join(self.FAKE_REPOS.git_root, 'repo_1')
self.assertFalse(scm.GIT.IsGitSvn(git_dir))
# Pure svn
svn_dir = scm.os.path.join(self.FAKE_REPOS.svn_checkout, 'trunk')
self.assertFalse(scm.GIT.IsGitSvn(svn_dir))
def testParseGitSvnSha1(self):
test_sha1 = 'a5c63ce8671922e5c59c0dea49ef4f9d4a3020c9'
expected_output = test_sha1 + '\n'
......
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