Commit cba46082 authored by Edward Lesmes's avatar Edward Lesmes Committed by LUCI CQ

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

This reverts commit e3a49aa4.

Reason for revert:

TypeError: expected str, bytes or os.PathLike object, not NoneType

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>

TBR=ehmaldonado@chromium.org,apolito@google.com,infra-scoped@luci-project-accounts.iam.gserviceaccount.com,sokcevic@google.com

Change-Id: I334a6289eb2c1f3e20feddd428307542d2aa38a9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2119411Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent e3a49aa4
......@@ -230,6 +230,18 @@ 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,7 +4,6 @@
"""SCM-specific utility classes."""
import distutils.version
import glob
import io
import os
......@@ -114,8 +113,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)
output = output.decode('utf-8', 'replace')
['git'] + args, cwd=cwd, stderr=subprocess2.PIPE, env=env,
**kwargs).decode('utf-8', 'replace')
return output.strip() if strip_out else output
@staticmethod
......@@ -407,7 +406,13 @@ 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'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)
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)
......@@ -214,6 +214,9 @@ 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,23 +38,6 @@ 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