Commit 50da7706 authored by Edward Lesmes's avatar Edward Lesmes Committed by LUCI CQ

Reland "git-cl: Remove unused and duplicate functions."

This is a reland of e3a49aa4

GetRelativeRoot was fixed to use '.' instead of None

Original change's description:
> git-cl: Remove unused and duplicate functions.
>
> Remove unused functions, and use scm.GIT where possible to reduce
> duplication.
>
> Change-Id: I24f05e7b3ae04743e97b6665ee668f44d6acc294
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2116938
> Reviewed-by: Anthony Polito <apolito@google.com>
> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>

Change-Id: I54bd1d34d3501a38bf8af2f9e70059d58fa538a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2125293Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 648b4cd2
......@@ -230,18 +230,6 @@ class GitWrapper(SCMWrapper):
filter_kwargs['predicate'] = self.out_cb
self.filter = gclient_utils.GitFilter(**filter_kwargs)
@staticmethod
def BinaryExists():
"""Returns true if the command exists."""
try:
# We assume git is newer than 1.7. See: crbug.com/114483
result, version = scm.GIT.AssertVersion('1.7')
if not result:
raise gclient_utils.Error('Git version is older than 1.7: %s' % version)
return result
except OSError:
return False
def GetCheckoutRoot(self):
return scm.GIT.GetCheckoutRoot(self.checkout_path)
......
This diff is collapsed.
......@@ -4,6 +4,7 @@
"""SCM-specific utility classes."""
import distutils.version
import glob
import io
import os
......@@ -113,8 +114,8 @@ class GIT(object):
def Capture(args, cwd, strip_out=True, **kwargs):
env = GIT.ApplyEnvVars(kwargs)
output = subprocess2.check_output(
['git'] + args, cwd=cwd, stderr=subprocess2.PIPE, env=env,
**kwargs).decode('utf-8', 'replace')
['git'] + args, cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs)
output = output.decode('utf-8', 'replace')
return output.strip() if strip_out else output
@staticmethod
......@@ -406,13 +407,7 @@ class GIT(object):
"""Asserts git's version is at least min_version."""
if cls.current_version is None:
current_version = cls.Capture(['--version'], '.')
matched = re.search(r'version ([0-9\.]+)', current_version)
cls.current_version = matched.group(1)
current_version_list = list(map(only_int, cls.current_version.split('.')))
for min_ver in map(int, min_version.split('.')):
ver = current_version_list.pop(0)
if ver < min_ver:
return (False, cls.current_version)
elif ver > min_ver:
return (True, cls.current_version)
return (True, cls.current_version)
matched = re.search(r'git version (.+)', current_version)
cls.current_version = distutils.version.LooseVersion(matched.group(1))
min_version = distutils.version.LooseVersion(min_version)
return (min_version <= cls.current_version, cls.current_version)
......@@ -214,9 +214,6 @@ from :3
self.relpath = '.'
self.base_path = join(self.root_dir, self.relpath)
self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
self._original_GitBinaryExists = gclient_scm.GitWrapper.BinaryExists
mock.patch('gclient_scm.GitWrapper.BinaryExists',
staticmethod(lambda : True)).start()
mock.patch('sys.stdout', StringIO()).start()
self.addCleanup(mock.patch.stopall)
self.addCleanup(gclient_utils.rmtree, self.root_dir)
......
This diff is collapsed.
......@@ -38,6 +38,23 @@ class GitWrapperTestCase(unittest.TestCase):
self.assertEqual(scm.GIT.GetEmail(self.root_dir), 'mini@me.com')
mockCapture.assert_called_with(['config', 'user.email'], cwd=self.root_dir)
@mock.patch('scm.GIT.Capture')
def testAssertVersion(self, mockCapture):
cases = [
('1.7', True),
('1.7.9', True),
('1.7.9.foo-bar-baz', True),
('1.8', True),
('1.6.9', False),
]
for expected_version, expected_ok in cases:
class GIT(scm.GIT):
pass
mockCapture.return_value = 'git version ' + expected_version
ok, version = GIT.AssertVersion('1.7')
self.assertEqual(expected_ok, ok)
self.assertEqual(expected_version, version)
def testRefToRemoteRef(self):
remote = 'origin'
refs = {
......
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