Commit 255b5d97 authored by borenet@google.com's avatar borenet@google.com

Re-reland r245404 ("If the destination directory doesn't contain the desired repo, delete it")

BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@250482 0039d316-1c4b-4281-b951-d872f2087c98
parent 7a54e818
......@@ -87,6 +87,7 @@ import platform
import posixpath
import pprint
import re
import socket
import sys
import time
import urllib
......@@ -668,6 +669,43 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
command, options, parsed_url, self.parent.name, revision_overrides)
self._used_scm = gclient_scm.CreateSCM(
parsed_url, self.root.root_dir, self.name)
def enable_deletion_of_conflicting_checkouts():
"""Determines whether to enable new checkout deletion behavior.
Initially, enables the experimental functionality on a small set of
bots.
"""
# TODO(borenet): Remove this hack as soon as we've verified that it
# doesn't cause the bots to break.
if not os.environ.get('CHROME_HEADLESS'):
return False
hostname = socket.gethostname()
logging.warning('Hostname of this machine: %s' % hostname)
return hostname in ('vm859-m1', 'build1-m1', 'vm630-m1')
# When updating, determine whether the destination directory contains a
# checkout of the desired repository. If not, avoid conflicts by
# deleting the directory before running the update.
if command == 'update' and enable_deletion_of_conflicting_checkouts():
logging.warning('Experimental deletion of mismatching checkouts '
'enabled.')
actual_remote_url = self._used_scm.GetRemoteURL(options)
url, _ = gclient_utils.SplitUrlRevision(parsed_url)
url = url.rstrip('/')
dest_dir = os.path.join(self.root.root_dir, self.name)
if os.path.isdir(dest_dir) and actual_remote_url != url:
if options.force:
logging.warning('%s does not contain a checkout of %s. Removing '
' %s' % (dest_dir, url, dest_dir))
gclient_utils.rmtree(dest_dir)
else:
raise gclient_utils.Error('%s does not contain a checkout of %s '
'(found %s instead). Please fix the '
'solution manually or run with --force '
'to delete automatically.' % (
dest_dir, url, actual_remote_url))
self._got_revision = self._used_scm.RunCommand(command, options, args,
file_list)
if file_list:
......
This diff is collapsed.
......@@ -166,12 +166,15 @@ class GIT(object):
return GIT.ShortBranchName(GIT.GetBranchRef(cwd))
@staticmethod
def IsGitSvn(cwd):
def IsGitSvn(checkout_root):
"""Returns true if this repo looks like it's using git-svn."""
# A git-svn checkout has a .git directory.
if not os.path.isdir(os.path.join(checkout_root, '.git')):
return False
# If you have any "svn-remote.*" config keys, we think you're using svn.
try:
GIT.Capture(['config', '--local', '--get-regexp', r'^svn-remote\.'],
cwd=cwd)
cwd=checkout_root)
return True
except subprocess2.CalledProcessError:
return False
......@@ -408,7 +411,7 @@ class GIT(object):
@staticmethod
def GetSha1ForSvnRev(cwd, rev):
"""Returns a corresponding git sha1 for a SVN revision."""
if not GIT.IsGitSvn(cwd=cwd):
if not GIT.IsGitSvn(cwd):
return None
try:
output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd)
......
This diff is collapsed.
......@@ -13,6 +13,7 @@ This test assumes GClientSmokeBase.URL_BASE is valid.
import logging
import os
import re
import socket
import subprocess
import sys
import unittest
......@@ -109,9 +110,9 @@ class GClientSmokeBase(FakeReposTestBase):
not re.match(
r'_____ [^ ]+ : Attempting rebase onto [0-9a-f]+...',
line) and
not re.match(r'_____ [^ ]+ at [^ ]+', line)):
# The two regexp above are a bit too broad, they are necessary only
# for git checkouts.
not re.match(r'_____ [^ ]+ at [^ ]+', line) and not
re.match(r'________ (.*) looks like git-svn; skipping.', line)):
# The regexp above are a bit too broad.
self.fail(line)
else:
results.append([[match.group(1), match.group(2), match.group(3)]])
......@@ -776,7 +777,56 @@ class GClientSmokeSVN(GClientSmokeBase):
# 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])
self.assertEquals(0, self.gclient(cmd + ['--force'])[-1])
def testSkipGitSvn(self):
# Check that gclient skips git-svn checkouts.
if not self.enabled:
return
# Create the .gclient file.
svn_url = self.svn_base + 'trunk/src'
self.gclient(['config', svn_url], cwd=self.root_dir)
# Create a git-svn checkout.
# Use check_output to hide the output from the subprocess.
subprocess2.check_output(['git', 'svn', 'clone', svn_url],
cwd=self.root_dir)
# Ensure that gclient skips the git-svn checkout.
stdout, stderr, rc = self.gclient(['sync', '--jobs', '1'])
self.assertEquals(rc, 0)
self.assertFalse(stderr)
self.assertTrue('________ src looks like git-svn; skipping.' in stdout)
self.checkBlock(stdout, [
['running', self.root_dir],
['running', os.path.join(self.root_dir, 'src', 'file', 'other')],
['running', self.root_dir],
['running', self.root_dir],
['running', self.root_dir],
['running', self.root_dir],
['running', self.root_dir],
])
# But, we still need the DEPS to be checked out...
foo_dir = os.path.join(self.root_dir, 'src', 'third_party', 'foo')
foo_rev = subprocess2.check_output(['svnversion', foo_dir]).strip()
self.assertEquals(foo_rev, '1')
other_dir = os.path.join(self.root_dir, 'src', 'other')
other_rev = subprocess2.check_output(['svnversion', other_dir]).strip()
self.assertEquals(other_rev, '2')
# Verify that the DEPS are NOT skipped on a second update.
stdout, stderr, rc = self.gclient(['sync', '--jobs', '1'])
self.assertFalse(stderr)
self.assertTrue('________ src looks like git-svn; skipping.' in stdout)
self.assertFalse(
'________ src/other looks like git-svn; skipping.' in stdout,
'Non git-svn checkout is incorrectly skipped.')
self.assertFalse(
'________ src/third_party/foo looks like git-svn; skipping.' in stdout,
'Non git-svn checkout is incorrectly skipped.')
class GClientSmokeSVNTransitive(GClientSmokeBase):
......@@ -1103,7 +1153,7 @@ class GClientSmokeGIT(GClientSmokeBase):
self.assertTree(tree)
# Pre-DEPS hooks run when syncing with --nohooks.
self.gclient(['sync', '--deps', 'mac', '--nohooks',
self.gclient(['sync', '--deps', 'mac', '--nohooks', '--force',
'--revision', 'src@' + self.githash('repo_5', 2)])
tree = self.mangle_git_tree(('repo_5@2', 'src'),
('repo_1@2', 'src/repo1'),
......@@ -1115,7 +1165,7 @@ class GClientSmokeGIT(GClientSmokeBase):
os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked'))
# Pre-DEPS hooks don't run with --noprehooks
self.gclient(['sync', '--deps', 'mac', '--noprehooks',
self.gclient(['sync', '--deps', 'mac', '--noprehooks', '--force',
'--revision', 'src@' + self.githash('repo_5', 2)])
tree = self.mangle_git_tree(('repo_5@2', 'src'),
('repo_1@2', 'src/repo1'),
......@@ -1343,6 +1393,81 @@ class GClientSmokeBoth(GClientSmokeBase):
self.assertEquals(sorted(entries), sorted(expected))
# TODO(borenet): Enable this at the same time that the guard is removed in
# gclient.
if (os.environ.get('CHROME_HEADLESS') and
socket.gethostname() in ('vm859-m1', 'build1-m1', 'vm630-m1')):
def testDeleteConflictingCheckout(self):
if not self.enabled:
return
# Create an initial svn checkout.
self.gclient(['config', '--spec',
'solutions=['
'{"name": "src",'
' "url": "' + self.svn_base + 'trunk/src"},'
']'
])
results = self.gclient(['sync', '--deps', 'mac'])
self.assertEqual(results[2], 0, 'Sync failed!')
# Verify that we have the expected svn checkout.
results = self.gclient(['revinfo', '--deps', 'mac'])
actual = results[0].splitlines()
expected = [
'src: %strunk/src' % self.svn_base,
'src/file/other: File("%strunk/other/DEPS")' % self.svn_base,
'src/other: %strunk/other' % self.svn_base,
'src/third_party/foo: %strunk/third_party/foo@1' % self.svn_base,
]
self.assertEquals(actual, expected)
# Change the desired checkout to git.
self.gclient(['config', '--spec',
'solutions=['
'{"name": "src",'
' "url": "' + self.git_base + 'repo_1"},'
']'
])
# Verify that the sync succeeds with --force.
results = self.gclient(['sync', '--deps', 'mac', '--force'])
self.assertEqual(results[2], 0, 'Sync failed!')
# Verify that we got the desired git checkout.
results = self.gclient(['revinfo', '--deps', 'mac'])
actual = results[0].splitlines()
expected = [
'src: %srepo_1' % self.git_base,
'src/repo2: %srepo_2@%s' % (self.git_base,
self.githash('repo_2', 1)[:7]),
'src/repo2/repo_renamed: %srepo_3' % self.git_base,
]
self.assertEquals(actual, expected)
# Change the desired checkout back to svn.
self.gclient(['config', '--spec',
'solutions=['
'{"name": "src",'
' "url": "' + self.svn_base + 'trunk/src"},'
']'
])
# Verify that the sync succeeds.
results = self.gclient(['sync', '--deps', 'mac', '--force'])
self.assertEqual(results[2], 0, 'Sync failed!')
# Verify that we have the expected svn checkout.
results = self.gclient(['revinfo', '--deps', 'mac'])
actual = results[0].splitlines()
expected = [
'src: %strunk/src' % self.svn_base,
'src/file/other: File("%strunk/other/DEPS")' % self.svn_base,
'src/other: %strunk/other' % self.svn_base,
'src/third_party/foo: %strunk/third_party/foo@1' % self.svn_base,
]
self.assertEquals(actual, expected)
class GClientSmokeFromCheckout(GClientSmokeBase):
# WebKit abuses this. It has a .gclient and a DEPS from a checkout.
......
......@@ -169,6 +169,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