|
|
@ -19,10 +19,15 @@ import sys
|
|
|
|
import tempfile
|
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if sys.version_info.major == 2:
|
|
|
|
|
|
|
|
from cStringIO import StringIO
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
from io import StringIO
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from third_party import mock
|
|
|
|
from testing_support import fake_repos
|
|
|
|
from testing_support import fake_repos
|
|
|
|
from testing_support.super_mox import mox, StdoutCheck, SuperMoxTestBase
|
|
|
|
|
|
|
|
from testing_support.super_mox import TestCaseUtils
|
|
|
|
from testing_support.super_mox import TestCaseUtils
|
|
|
|
|
|
|
|
|
|
|
|
import gclient_scm
|
|
|
|
import gclient_scm
|
|
|
@ -38,73 +43,37 @@ join = gclient_scm.os.path.join
|
|
|
|
TIMESTAMP_RE = re.compile('\[[0-9]{1,2}:[0-9]{2}:[0-9]{2}\] (.*)', re.DOTALL)
|
|
|
|
TIMESTAMP_RE = re.compile('\[[0-9]{1,2}:[0-9]{2}:[0-9]{2}\] (.*)', re.DOTALL)
|
|
|
|
def strip_timestamps(value):
|
|
|
|
def strip_timestamps(value):
|
|
|
|
lines = value.splitlines(True)
|
|
|
|
lines = value.splitlines(True)
|
|
|
|
for i in xrange(len(lines)):
|
|
|
|
for i in range(len(lines)):
|
|
|
|
m = TIMESTAMP_RE.match(lines[i])
|
|
|
|
m = TIMESTAMP_RE.match(lines[i])
|
|
|
|
if m:
|
|
|
|
if m:
|
|
|
|
lines[i] = m.group(1)
|
|
|
|
lines[i] = m.group(1)
|
|
|
|
return ''.join(lines)
|
|
|
|
return ''.join(lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GCBaseTestCase(object):
|
|
|
|
class BasicTests(unittest.TestCase):
|
|
|
|
def assertRaisesError(self, msg, fn, *args, **kwargs):
|
|
|
|
@mock.patch('gclient_scm.scm.GIT.Capture')
|
|
|
|
"""Like unittest's assertRaises() but checks for Gclient.Error."""
|
|
|
|
def testGetFirstRemoteUrl(self, mockCapture):
|
|
|
|
try:
|
|
|
|
|
|
|
|
fn(*args, **kwargs)
|
|
|
|
|
|
|
|
except gclient_scm.gclient_utils.Error as e:
|
|
|
|
|
|
|
|
self.assertEquals(e.args[0], msg)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.fail('%s not raised' % msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseTestCase(GCBaseTestCase, SuperMoxTestBase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
|
|
|
SuperMoxTestBase.setUp(self)
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter')
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead')
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'rmtree')
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(subprocess2, 'communicate')
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(subprocess2, 'Popen')
|
|
|
|
|
|
|
|
self._scm_wrapper = gclient_scm.GitWrapper
|
|
|
|
|
|
|
|
self._original_GitBinaryExists = gclient_scm.GitWrapper.BinaryExists
|
|
|
|
|
|
|
|
gclient_scm.GitWrapper.BinaryExists = staticmethod(lambda : True)
|
|
|
|
|
|
|
|
# Absolute path of the fake checkout directory.
|
|
|
|
|
|
|
|
self.base_path = join(self.root_dir, self.relpath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
|
|
|
SuperMoxTestBase.tearDown(self)
|
|
|
|
|
|
|
|
gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BasicTests(SuperMoxTestBase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
|
|
|
SuperMoxTestBase.setUp(self)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testGetFirstRemoteUrl(self):
|
|
|
|
|
|
|
|
REMOTE_STRINGS = [('remote.origin.url E:\\foo\\bar', 'E:\\foo\\bar'),
|
|
|
|
REMOTE_STRINGS = [('remote.origin.url E:\\foo\\bar', 'E:\\foo\\bar'),
|
|
|
|
('remote.origin.url /b/foo/bar', '/b/foo/bar'),
|
|
|
|
('remote.origin.url /b/foo/bar', '/b/foo/bar'),
|
|
|
|
('remote.origin.url https://foo/bar', 'https://foo/bar'),
|
|
|
|
('remote.origin.url https://foo/bar', 'https://foo/bar'),
|
|
|
|
('remote.origin.url E:\\Fo Bar\\bax', 'E:\\Fo Bar\\bax'),
|
|
|
|
('remote.origin.url E:\\Fo Bar\\bax', 'E:\\Fo Bar\\bax'),
|
|
|
|
('remote.origin.url git://what/"do', 'git://what/"do')]
|
|
|
|
('remote.origin.url git://what/"do', 'git://what/"do')]
|
|
|
|
FAKE_PATH = '/fake/path'
|
|
|
|
FAKE_PATH = '/fake/path'
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture')
|
|
|
|
mockCapture.side_effect = [question for question, _ in REMOTE_STRINGS]
|
|
|
|
for question, _ in REMOTE_STRINGS:
|
|
|
|
|
|
|
|
gclient_scm.scm.GIT.Capture(
|
|
|
|
|
|
|
|
['config', '--local', '--get-regexp', r'remote.*.url'],
|
|
|
|
|
|
|
|
cwd=FAKE_PATH).AndReturn(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.ReplayAll()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, answer in REMOTE_STRINGS:
|
|
|
|
for _, answer in REMOTE_STRINGS:
|
|
|
|
self.assertEquals(gclient_scm.SCMWrapper._get_first_remote_url(FAKE_PATH),
|
|
|
|
self.assertEqual(
|
|
|
|
answer)
|
|
|
|
gclient_scm.SCMWrapper._get_first_remote_url(FAKE_PATH), answer)
|
|
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
expected_calls = [
|
|
|
|
SuperMoxTestBase.tearDown(self)
|
|
|
|
mock.call(['config', '--local', '--get-regexp', r'remote.*.url'],
|
|
|
|
|
|
|
|
cwd=FAKE_PATH)
|
|
|
|
|
|
|
|
for _ in REMOTE_STRINGS
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
self.assertEqual(mockCapture.mock_calls, expected_calls)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils,
|
|
|
|
class BaseGitWrapperTestCase(unittest.TestCase, TestCaseUtils):
|
|
|
|
unittest.TestCase):
|
|
|
|
|
|
|
|
"""This class doesn't use pymox."""
|
|
|
|
"""This class doesn't use pymox."""
|
|
|
|
class OptionsObject(object):
|
|
|
|
class OptionsObject(object):
|
|
|
|
def __init__(self, verbose=False, revision=None):
|
|
|
|
def __init__(self, verbose=False, revision=None):
|
|
|
@ -193,7 +162,7 @@ from :3
|
|
|
|
value = sys.stdout.getvalue()
|
|
|
|
value = sys.stdout.getvalue()
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
# pylint: disable=no-member
|
|
|
|
# pylint: disable=no-member
|
|
|
|
self.assertEquals(expected, strip_timestamps(value))
|
|
|
|
self.assertEqual(expected, strip_timestamps(value))
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@staticmethod
|
|
|
|
def CreateGitRepo(git_import, path):
|
|
|
|
def CreateGitRepo(git_import, path):
|
|
|
@ -205,7 +174,7 @@ from :3
|
|
|
|
# git is not available, skip this test.
|
|
|
|
# git is not available, skip this test.
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
Popen(['git', 'fast-import', '--quiet'], stdin=PIPE, stdout=PIPE,
|
|
|
|
Popen(['git', 'fast-import', '--quiet'], stdin=PIPE, stdout=PIPE,
|
|
|
|
stderr=STDOUT, cwd=path).communicate(input=git_import)
|
|
|
|
stderr=STDOUT, cwd=path).communicate(input=git_import.encode())
|
|
|
|
Popen(['git', 'checkout', '-q'], stdout=PIPE, stderr=STDOUT,
|
|
|
|
Popen(['git', 'checkout', '-q'], stdout=PIPE, stderr=STDOUT,
|
|
|
|
cwd=path).communicate()
|
|
|
|
cwd=path).communicate()
|
|
|
|
Popen(['git', 'remote', 'add', '-f', 'origin', '.'], stdout=PIPE,
|
|
|
|
Popen(['git', 'remote', 'add', '-f', 'origin', '.'], stdout=PIPE,
|
|
|
@ -224,13 +193,13 @@ from :3
|
|
|
|
|
|
|
|
|
|
|
|
def _GetAskForDataCallback(self, expected_prompt, return_value):
|
|
|
|
def _GetAskForDataCallback(self, expected_prompt, return_value):
|
|
|
|
def AskForData(prompt, options):
|
|
|
|
def AskForData(prompt, options):
|
|
|
|
self.assertEquals(prompt, expected_prompt)
|
|
|
|
self.assertEqual(prompt, expected_prompt)
|
|
|
|
return return_value
|
|
|
|
return return_value
|
|
|
|
return AskForData
|
|
|
|
return AskForData
|
|
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
def setUp(self):
|
|
|
|
TestCaseUtils.setUp(self)
|
|
|
|
|
|
|
|
unittest.TestCase.setUp(self)
|
|
|
|
unittest.TestCase.setUp(self)
|
|
|
|
|
|
|
|
TestCaseUtils.setUp(self)
|
|
|
|
self.url = 'git://foo'
|
|
|
|
self.url = 'git://foo'
|
|
|
|
# The .git suffix allows gclient_scm to recognize the dir as a git repo
|
|
|
|
# The .git suffix allows gclient_scm to recognize the dir as a git repo
|
|
|
|
# when cloning it locally
|
|
|
|
# when cloning it locally
|
|
|
@ -238,19 +207,12 @@ from :3
|
|
|
|
self.relpath = '.'
|
|
|
|
self.relpath = '.'
|
|
|
|
self.base_path = join(self.root_dir, self.relpath)
|
|
|
|
self.base_path = join(self.root_dir, self.relpath)
|
|
|
|
self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
|
|
|
|
self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
|
|
|
|
StdoutCheck.setUp(self)
|
|
|
|
|
|
|
|
self._original_GitBinaryExists = gclient_scm.GitWrapper.BinaryExists
|
|
|
|
self._original_GitBinaryExists = gclient_scm.GitWrapper.BinaryExists
|
|
|
|
gclient_scm.GitWrapper.BinaryExists = staticmethod(lambda : True)
|
|
|
|
mock.patch('gclient_scm.GitWrapper.BinaryExists',
|
|
|
|
|
|
|
|
staticmethod(lambda : True)).start()
|
|
|
|
def tearDown(self):
|
|
|
|
mock.patch('sys.stdout', StringIO()).start()
|
|
|
|
try:
|
|
|
|
self.addCleanup(mock.patch.stopall)
|
|
|
|
rmtree(self.root_dir)
|
|
|
|
self.addCleanup(lambda: rmtree(self.root_dir))
|
|
|
|
StdoutCheck.tearDown(self)
|
|
|
|
|
|
|
|
TestCaseUtils.tearDown(self)
|
|
|
|
|
|
|
|
unittest.TestCase.tearDown(self)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
# TODO(maruel): Use auto_stub.TestCase.
|
|
|
|
|
|
|
|
gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
@ -267,10 +229,10 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
gclient_scm.os.remove(file_path)
|
|
|
|
gclient_scm.os.remove(file_path)
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.revert(options, self.args, file_list)
|
|
|
|
scm.revert(options, self.args, file_list)
|
|
|
|
self.assertEquals(file_list, [file_path])
|
|
|
|
self.assertEqual(file_list, [file_path])
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.diff(options, self.args, file_list)
|
|
|
|
scm.diff(options, self.args, file_list)
|
|
|
|
self.assertEquals(file_list, [])
|
|
|
|
self.assertEqual(file_list, [])
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
|
def testRevertNone(self):
|
|
|
|
def testRevertNone(self):
|
|
|
@ -283,9 +245,9 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
scm.update(options, None, file_list)
|
|
|
|
scm.update(options, None, file_list)
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.revert(options, self.args, file_list)
|
|
|
|
scm.revert(options, self.args, file_list)
|
|
|
|
self.assertEquals(file_list, [])
|
|
|
|
self.assertEqual(file_list, [])
|
|
|
|
self.assertEquals(scm.revinfo(options, self.args, None),
|
|
|
|
self.assertEqual(scm.revinfo(options, self.args, None),
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
|
def testRevertModified(self):
|
|
|
|
def testRevertModified(self):
|
|
|
@ -297,14 +259,15 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.update(options, None, file_list)
|
|
|
|
scm.update(options, None, file_list)
|
|
|
|
file_path = join(self.base_path, 'a')
|
|
|
|
file_path = join(self.base_path, 'a')
|
|
|
|
open(file_path, 'a').writelines('touched\n')
|
|
|
|
with open(file_path, 'a') as f:
|
|
|
|
|
|
|
|
f.writelines('touched\n')
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.revert(options, self.args, file_list)
|
|
|
|
scm.revert(options, self.args, file_list)
|
|
|
|
self.assertEquals(file_list, [file_path])
|
|
|
|
self.assertEqual(file_list, [file_path])
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.diff(options, self.args, file_list)
|
|
|
|
scm.diff(options, self.args, file_list)
|
|
|
|
self.assertEquals(file_list, [])
|
|
|
|
self.assertEqual(file_list, [])
|
|
|
|
self.assertEquals(scm.revinfo(options, self.args, None),
|
|
|
|
self.assertEqual(scm.revinfo(options, self.args, None),
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
@ -317,19 +280,18 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.update(options, None, file_list)
|
|
|
|
scm.update(options, None, file_list)
|
|
|
|
file_path = join(self.base_path, 'c')
|
|
|
|
file_path = join(self.base_path, 'c')
|
|
|
|
f = open(file_path, 'w')
|
|
|
|
with open(file_path, 'w') as f:
|
|
|
|
f.writelines('new\n')
|
|
|
|
f.writelines('new\n')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
Popen(['git', 'add', 'c'], stdout=PIPE,
|
|
|
|
Popen(['git', 'add', 'c'], stdout=PIPE,
|
|
|
|
stderr=STDOUT, cwd=self.base_path).communicate()
|
|
|
|
stderr=STDOUT, cwd=self.base_path).communicate()
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.revert(options, self.args, file_list)
|
|
|
|
scm.revert(options, self.args, file_list)
|
|
|
|
self.assertEquals(file_list, [file_path])
|
|
|
|
self.assertEqual(file_list, [file_path])
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.diff(options, self.args, file_list)
|
|
|
|
scm.diff(options, self.args, file_list)
|
|
|
|
self.assertEquals(file_list, [])
|
|
|
|
self.assertEqual(file_list, [])
|
|
|
|
self.assertEquals(scm.revinfo(options, self.args, None),
|
|
|
|
self.assertEqual(scm.revinfo(options, self.args, None),
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
|
def testStatusNew(self):
|
|
|
|
def testStatusNew(self):
|
|
|
@ -337,12 +299,13 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
options = self.Options()
|
|
|
|
options = self.Options()
|
|
|
|
file_path = join(self.base_path, 'a')
|
|
|
|
file_path = join(self.base_path, 'a')
|
|
|
|
open(file_path, 'a').writelines('touched\n')
|
|
|
|
with open(file_path, 'a') as f:
|
|
|
|
|
|
|
|
f.writelines('touched\n')
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.status(options, self.args, file_list)
|
|
|
|
scm.status(options, self.args, file_list)
|
|
|
|
self.assertEquals(file_list, [file_path])
|
|
|
|
self.assertEqual(file_list, [file_path])
|
|
|
|
self.checkstdout(
|
|
|
|
self.checkstdout(
|
|
|
|
('\n________ running \'git -c core.quotePath=false diff --name-status '
|
|
|
|
('\n________ running \'git -c core.quotePath=false diff --name-status '
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\n\nM\ta\n') %
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\n\nM\ta\n') %
|
|
|
@ -355,14 +318,15 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
expected_file_list = []
|
|
|
|
expected_file_list = []
|
|
|
|
for f in ['a', 'b']:
|
|
|
|
for f in ['a', 'b']:
|
|
|
|
file_path = join(self.base_path, f)
|
|
|
|
file_path = join(self.base_path, f)
|
|
|
|
open(file_path, 'a').writelines('touched\n')
|
|
|
|
with open(file_path, 'a') as f:
|
|
|
|
|
|
|
|
f.writelines('touched\n')
|
|
|
|
expected_file_list.extend([file_path])
|
|
|
|
expected_file_list.extend([file_path])
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.status(options, self.args, file_list)
|
|
|
|
scm.status(options, self.args, file_list)
|
|
|
|
expected_file_list = [join(self.base_path, x) for x in ['a', 'b']]
|
|
|
|
expected_file_list = [join(self.base_path, x) for x in ['a', 'b']]
|
|
|
|
self.assertEquals(sorted(file_list), expected_file_list)
|
|
|
|
self.assertEqual(sorted(file_list), expected_file_list)
|
|
|
|
self.checkstdout(
|
|
|
|
self.checkstdout(
|
|
|
|
('\n________ running \'git -c core.quotePath=false diff --name-status '
|
|
|
|
('\n________ running \'git -c core.quotePath=false diff --name-status '
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\n\nM\ta\nM\tb\n')
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\n\nM\ta\nM\tb\n')
|
|
|
@ -377,8 +341,8 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
self.assertEquals(file_list, expected_file_list)
|
|
|
|
self.assertEqual(file_list, expected_file_list)
|
|
|
|
self.assertEquals(scm.revinfo(options, (), None),
|
|
|
|
self.assertEqual(scm.revinfo(options, (), None),
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
@ -393,15 +357,15 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
rev = scm.revinfo(options, (), None)
|
|
|
|
rev = scm.revinfo(options, (), None)
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
self.assertEquals(file_list, [join(self.base_path, x)
|
|
|
|
self.assertEqual(file_list, [join(self.base_path, x)
|
|
|
|
for x in ['a', 'b', 'c']])
|
|
|
|
for x in ['a', 'b', 'c']])
|
|
|
|
# The actual commit that is created is unstable, so we verify its tree and
|
|
|
|
# The actual commit that is created is unstable, so we verify its tree and
|
|
|
|
# parents instead.
|
|
|
|
# parents instead.
|
|
|
|
self.assertEquals(scm._Capture(['rev-parse', 'HEAD:']),
|
|
|
|
self.assertEqual(scm._Capture(['rev-parse', 'HEAD:']),
|
|
|
|
'd2e35c10ac24d6c621e14a1fcadceb533155627d')
|
|
|
|
'd2e35c10ac24d6c621e14a1fcadceb533155627d')
|
|
|
|
self.assertEquals(scm._Capture(['rev-parse', 'HEAD^1']), rev)
|
|
|
|
self.assertEqual(scm._Capture(['rev-parse', 'HEAD^1']), rev)
|
|
|
|
self.assertEquals(scm._Capture(['rev-parse', 'HEAD^2']),
|
|
|
|
self.assertEqual(scm._Capture(['rev-parse', 'HEAD^2']),
|
|
|
|
scm._Capture(['rev-parse', 'origin/master']))
|
|
|
|
scm._Capture(['rev-parse', 'origin/master']))
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
|
def testUpdateRebase(self):
|
|
|
|
def testUpdateRebase(self):
|
|
|
@ -417,14 +381,14 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
'Cannot fast-forward merge, attempt to rebase? '
|
|
|
|
'Cannot fast-forward merge, attempt to rebase? '
|
|
|
|
'(y)es / (q)uit / (s)kip : ', 'y')
|
|
|
|
'(y)es / (q)uit / (s)kip : ', 'y')
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
self.assertEquals(file_list, [join(self.base_path, x)
|
|
|
|
self.assertEqual(file_list, [join(self.base_path, x)
|
|
|
|
for x in ['a', 'b', 'c']])
|
|
|
|
for x in ['a', 'b', 'c']])
|
|
|
|
# The actual commit that is created is unstable, so we verify its tree and
|
|
|
|
# The actual commit that is created is unstable, so we verify its tree and
|
|
|
|
# parent instead.
|
|
|
|
# parent instead.
|
|
|
|
self.assertEquals(scm._Capture(['rev-parse', 'HEAD:']),
|
|
|
|
self.assertEqual(scm._Capture(['rev-parse', 'HEAD:']),
|
|
|
|
'd2e35c10ac24d6c621e14a1fcadceb533155627d')
|
|
|
|
'd2e35c10ac24d6c621e14a1fcadceb533155627d')
|
|
|
|
self.assertEquals(scm._Capture(['rev-parse', 'HEAD^']),
|
|
|
|
self.assertEqual(scm._Capture(['rev-parse', 'HEAD^']),
|
|
|
|
scm._Capture(['rev-parse', 'origin/master']))
|
|
|
|
scm._Capture(['rev-parse', 'origin/master']))
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
|
def testUpdateReset(self):
|
|
|
|
def testUpdateReset(self):
|
|
|
@ -435,10 +399,12 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
|
|
|
|
|
|
|
|
dir_path = join(self.base_path, 'c')
|
|
|
|
dir_path = join(self.base_path, 'c')
|
|
|
|
os.mkdir(dir_path)
|
|
|
|
os.mkdir(dir_path)
|
|
|
|
open(join(dir_path, 'nested'), 'w').writelines('new\n')
|
|
|
|
with open(join(dir_path, 'nested'), 'w') as f:
|
|
|
|
|
|
|
|
f.writelines('new\n')
|
|
|
|
|
|
|
|
|
|
|
|
file_path = join(self.base_path, 'file')
|
|
|
|
file_path = join(self.base_path, 'file')
|
|
|
|
open(file_path, 'w').writelines('new\n')
|
|
|
|
with open(file_path, 'w') as f:
|
|
|
|
|
|
|
|
f.writelines('new\n')
|
|
|
|
|
|
|
|
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
@ -461,8 +427,8 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
|
|
|
|
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
self.assertEquals(scm.revinfo(options, (), None),
|
|
|
|
self.assertEqual(scm.revinfo(options, (), None),
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458')
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458')
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
|
def testUpdateResetDeleteUnversionedTrees(self):
|
|
|
|
def testUpdateResetDeleteUnversionedTrees(self):
|
|
|
@ -474,10 +440,12 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
|
|
|
|
|
|
|
|
dir_path = join(self.base_path, 'dir')
|
|
|
|
dir_path = join(self.base_path, 'dir')
|
|
|
|
os.mkdir(dir_path)
|
|
|
|
os.mkdir(dir_path)
|
|
|
|
open(join(dir_path, 'nested'), 'w').writelines('new\n')
|
|
|
|
with open(join(dir_path, 'nested'), 'w') as f:
|
|
|
|
|
|
|
|
f.writelines('new\n')
|
|
|
|
|
|
|
|
|
|
|
|
file_path = join(self.base_path, 'file')
|
|
|
|
file_path = join(self.base_path, 'file')
|
|
|
|
open(file_path, 'w').writelines('new\n')
|
|
|
|
with open(file_path, 'w') as f:
|
|
|
|
|
|
|
|
f.writelines('new\n')
|
|
|
|
|
|
|
|
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
@ -494,7 +462,8 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
|
file_path = join(self.base_path, 'b')
|
|
|
|
file_path = join(self.base_path, 'b')
|
|
|
|
open(file_path, 'w').writelines('conflict\n')
|
|
|
|
with open(file_path, 'w') as f:
|
|
|
|
|
|
|
|
f.writelines('conflict\n')
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
scm.update(options, (), [])
|
|
|
|
scm.update(options, (), [])
|
|
|
|
self.fail()
|
|
|
|
self.fail()
|
|
|
@ -544,19 +513,29 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
|
file_path = join(self.base_path, 'b')
|
|
|
|
file_path = join(self.base_path, 'b')
|
|
|
|
open(file_path, 'w').writelines('conflict\n')
|
|
|
|
with open(file_path, 'w') as f:
|
|
|
|
|
|
|
|
f.writelines('conflict\n')
|
|
|
|
scm._Run(['commit', '-am', 'test'], options)
|
|
|
|
scm._Run(['commit', '-am', 'test'], options)
|
|
|
|
scm._AskForData = self._GetAskForDataCallback(
|
|
|
|
scm._AskForData = self._GetAskForDataCallback(
|
|
|
|
'Cannot fast-forward merge, attempt to rebase? '
|
|
|
|
'Cannot fast-forward merge, attempt to rebase? '
|
|
|
|
'(y)es / (q)uit / (s)kip : ', 'y')
|
|
|
|
'(y)es / (q)uit / (s)kip : ', 'y')
|
|
|
|
exception = ('Conflict while rebasing this branch.\n'
|
|
|
|
|
|
|
|
'Fix the conflict and run gclient again.\n'
|
|
|
|
with self.assertRaises(gclient_scm.gclient_utils.Error) as e:
|
|
|
|
'See \'man git-rebase\' for details.\n')
|
|
|
|
scm.update(options, (), [])
|
|
|
|
self.assertRaisesError(exception, scm.update, options, (), [])
|
|
|
|
self.assertEqual(
|
|
|
|
exception = ('\n____ . at refs/remotes/origin/master\n'
|
|
|
|
e.exception.args[0],
|
|
|
|
'\tYou have unstaged changes.\n'
|
|
|
|
'Conflict while rebasing this branch.\n'
|
|
|
|
'\tPlease commit, stash, or reset.\n')
|
|
|
|
'Fix the conflict and run gclient again.\n'
|
|
|
|
self.assertRaisesError(exception, scm.update, options, (), [])
|
|
|
|
'See \'man git-rebase\' for details.\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(gclient_scm.gclient_utils.Error) as e:
|
|
|
|
|
|
|
|
scm.update(options, (), [])
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
|
|
|
e.exception.args[0],
|
|
|
|
|
|
|
|
'\n____ . at refs/remotes/origin/master\n'
|
|
|
|
|
|
|
|
'\tYou have unstaged changes.\n'
|
|
|
|
|
|
|
|
'\tPlease commit, stash, or reset.\n')
|
|
|
|
|
|
|
|
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
|
def testRevinfo(self):
|
|
|
|
def testRevinfo(self):
|
|
|
@ -566,7 +545,7 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
|
rev_info = scm.revinfo(options, (), None)
|
|
|
|
rev_info = scm.revinfo(options, (), None)
|
|
|
|
self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
|
|
|
|
self.assertEqual(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
|
|
|
|
|
|
|
|
|
|
|
|
def testMirrorPushUrl(self):
|
|
|
|
def testMirrorPushUrl(self):
|
|
|
|
if not self.enabled:
|
|
|
|
if not self.enabled:
|
|
|
@ -600,11 +579,11 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
' fetch_url: %s' % fetch_url,
|
|
|
|
' fetch_url: %s' % fetch_url,
|
|
|
|
' mirror: %s' % mirror]))
|
|
|
|
' mirror: %s' % mirror]))
|
|
|
|
push_url = scm._Capture(['remote', 'get-url', '--push', 'origin'])
|
|
|
|
push_url = scm._Capture(['remote', 'get-url', '--push', 'origin'])
|
|
|
|
self.assertEquals(push_url, self.url)
|
|
|
|
self.assertEqual(push_url, self.url)
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ManagedGitWrapperTestCaseMox(BaseTestCase):
|
|
|
|
class ManagedGitWrapperTestCaseMock(unittest.TestCase):
|
|
|
|
class OptionsObject(object):
|
|
|
|
class OptionsObject(object):
|
|
|
|
def __init__(self, verbose=False, revision=None, force=False):
|
|
|
|
def __init__(self, verbose=False, revision=None, force=False):
|
|
|
|
self.verbose = verbose
|
|
|
|
self.verbose = verbose
|
|
|
@ -627,10 +606,9 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase):
|
|
|
|
value = sys.stdout.getvalue()
|
|
|
|
value = sys.stdout.getvalue()
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
# pylint: disable=no-member
|
|
|
|
# pylint: disable=no-member
|
|
|
|
self.assertEquals(expected, strip_timestamps(value))
|
|
|
|
self.assertEqual(expected, strip_timestamps(value))
|
|
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
def setUp(self):
|
|
|
|
BaseTestCase.setUp(self)
|
|
|
|
|
|
|
|
self.fake_hash_1 = 't0ta11yf4k3'
|
|
|
|
self.fake_hash_1 = 't0ta11yf4k3'
|
|
|
|
self.fake_hash_2 = '3v3nf4k3r'
|
|
|
|
self.fake_hash_2 = '3v3nf4k3r'
|
|
|
|
self.url = 'git://foo'
|
|
|
|
self.url = 'git://foo'
|
|
|
@ -639,107 +617,94 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase):
|
|
|
|
self.base_path = os.path.join(self.root_dir, self.relpath)
|
|
|
|
self.base_path = os.path.join(self.root_dir, self.relpath)
|
|
|
|
self.backup_base_path = os.path.join(self.root_dir,
|
|
|
|
self.backup_base_path = os.path.join(self.root_dir,
|
|
|
|
'old_%s.git' % self.relpath)
|
|
|
|
'old_%s.git' % self.relpath)
|
|
|
|
|
|
|
|
mock.patch('gclient_scm.scm.GIT.ApplyEnvVars').start()
|
|
|
|
def tearDown(self):
|
|
|
|
mock.patch('gclient_scm.GitWrapper._CheckMinVersion').start()
|
|
|
|
BaseTestCase.tearDown(self)
|
|
|
|
mock.patch('gclient_scm.GitWrapper._Fetch').start()
|
|
|
|
|
|
|
|
mock.patch('gclient_scm.GitWrapper._DeleteOrMove').start()
|
|
|
|
def testGetUsableRevGit(self):
|
|
|
|
mock.patch('sys.stdout', StringIO()).start()
|
|
|
|
|
|
|
|
self.addCleanup(mock.patch.stopall)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch('scm.GIT.IsValidRevision')
|
|
|
|
|
|
|
|
@mock.patch('os.path.isdir', lambda _: True)
|
|
|
|
|
|
|
|
def testGetUsableRevGit(self, mockIsValidRevision):
|
|
|
|
# pylint: disable=no-member
|
|
|
|
# pylint: disable=no-member
|
|
|
|
options = self.Options(verbose=True)
|
|
|
|
options = self.Options(verbose=True)
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True)
|
|
|
|
mockIsValidRevision.side_effect = lambda cwd, rev: rev != '1'
|
|
|
|
gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1
|
|
|
|
|
|
|
|
).AndReturn(True)
|
|
|
|
|
|
|
|
gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev='1'
|
|
|
|
|
|
|
|
).AndReturn(False)
|
|
|
|
|
|
|
|
gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev='1'
|
|
|
|
|
|
|
|
).AndReturn(False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Fetch', True)
|
|
|
|
|
|
|
|
# pylint: disable=no-value-for-parameter
|
|
|
|
|
|
|
|
gclient_scm.GitWrapper._Fetch(options).AndReturn(None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gclient_scm.scm.os.path.isdir(self.base_path).AndReturn(True)
|
|
|
|
|
|
|
|
gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.ReplayAll()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
git_scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
git_scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
|
# A [fake] git sha1 with a git repo should work (this is in the case that
|
|
|
|
# A [fake] git sha1 with a git repo should work (this is in the case that
|
|
|
|
# the LKGR gets flipped to git sha1's some day).
|
|
|
|
# the LKGR gets flipped to git sha1's some day).
|
|
|
|
self.assertEquals(git_scm.GetUsableRev(self.fake_hash_1, options),
|
|
|
|
self.assertEqual(git_scm.GetUsableRev(self.fake_hash_1, options),
|
|
|
|
self.fake_hash_1)
|
|
|
|
self.fake_hash_1)
|
|
|
|
# An SVN rev with an existing purely git repo should raise an exception.
|
|
|
|
# An SVN rev with an existing purely git repo should raise an exception.
|
|
|
|
self.assertRaises(gclient_scm.gclient_utils.Error,
|
|
|
|
self.assertRaises(gclient_scm.gclient_utils.Error,
|
|
|
|
git_scm.GetUsableRev, '1', options)
|
|
|
|
git_scm.GetUsableRev, '1', options)
|
|
|
|
|
|
|
|
|
|
|
|
def testUpdateNoDotGit(self):
|
|
|
|
@mock.patch('gclient_scm.GitWrapper._Clone')
|
|
|
|
options = self.Options()
|
|
|
|
@mock.patch('os.path.isdir')
|
|
|
|
|
|
|
|
@mock.patch('os.path.exists')
|
|
|
|
|
|
|
|
@mock.patch('subprocess2.check_output')
|
|
|
|
|
|
|
|
def testUpdateNoDotGit(
|
|
|
|
|
|
|
|
self, mockCheckOutput, mockExists, mockIsdir, mockClone):
|
|
|
|
|
|
|
|
mockIsdir.side_effect = lambda path: path == self.base_path
|
|
|
|
|
|
|
|
mockExists.side_effect = lambda path: path == self.base_path
|
|
|
|
|
|
|
|
mockCheckOutput.return_value = b''
|
|
|
|
|
|
|
|
|
|
|
|
gclient_scm.os.path.isdir(
|
|
|
|
options = self.Options()
|
|
|
|
os.path.join(self.base_path, '.git', 'hooks')).AndReturn(False)
|
|
|
|
scm = gclient_scm.GitWrapper(
|
|
|
|
gclient_scm.os.path.exists(self.backup_base_path).AndReturn(False)
|
|
|
|
self.url, self.root_dir, self.relpath)
|
|
|
|
gclient_scm.os.path.exists(self.base_path).AndReturn(True)
|
|
|
|
|
|
|
|
gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
|
|
|
|
|
|
|
|
gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
|
|
|
|
|
|
|
|
).AndReturn(False)
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
|
|
|
|
|
|
|
|
# pylint: disable=no-value-for-parameter
|
|
|
|
|
|
|
|
gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
|
|
|
|
|
|
|
|
options)
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
|
|
|
|
|
|
|
|
gclient_scm.subprocess2.check_output(
|
|
|
|
|
|
|
|
['git', '-c', 'core.quotePath=false', 'ls-files'], cwd=self.base_path,
|
|
|
|
|
|
|
|
env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('')
|
|
|
|
|
|
|
|
gclient_scm.subprocess2.check_output(
|
|
|
|
|
|
|
|
['git', 'rev-parse', '--verify', 'HEAD'],
|
|
|
|
|
|
|
|
cwd=self.base_path,
|
|
|
|
|
|
|
|
env=gclient_scm.scm.GIT.ApplyEnvVars({}),
|
|
|
|
|
|
|
|
stderr=-1,
|
|
|
|
|
|
|
|
).AndReturn('')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.ReplayAll()
|
|
|
|
|
|
|
|
scm = self._scm_wrapper(self.url, self.root_dir,
|
|
|
|
|
|
|
|
self.relpath)
|
|
|
|
|
|
|
|
scm.update(options, None, [])
|
|
|
|
scm.update(options, None, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
env = gclient_scm.scm.GIT.ApplyEnvVars({})
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
|
|
|
mockCheckOutput.mock_calls,
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
mock.call(
|
|
|
|
|
|
|
|
['git', '-c', 'core.quotePath=false', 'ls-files'],
|
|
|
|
|
|
|
|
cwd=self.base_path, env=env, stderr=-1),
|
|
|
|
|
|
|
|
mock.call(
|
|
|
|
|
|
|
|
['git', 'rev-parse', '--verify', 'HEAD'],
|
|
|
|
|
|
|
|
cwd=self.base_path, env=env, stderr=-1),
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
mockClone.assert_called_with(
|
|
|
|
|
|
|
|
'refs/remotes/origin/master', self.url, options)
|
|
|
|
self.checkstdout('\n')
|
|
|
|
self.checkstdout('\n')
|
|
|
|
|
|
|
|
|
|
|
|
def testUpdateConflict(self):
|
|
|
|
@mock.patch('gclient_scm.GitWrapper._Clone')
|
|
|
|
options = self.Options()
|
|
|
|
@mock.patch('os.path.isdir')
|
|
|
|
|
|
|
|
@mock.patch('os.path.exists')
|
|
|
|
|
|
|
|
@mock.patch('subprocess2.check_output')
|
|
|
|
|
|
|
|
def testUpdateConflict(
|
|
|
|
|
|
|
|
self, mockCheckOutput, mockExists, mockIsdir, mockClone):
|
|
|
|
|
|
|
|
mockIsdir.side_effect = lambda path: path == self.base_path
|
|
|
|
|
|
|
|
mockExists.side_effect = lambda path: path == self.base_path
|
|
|
|
|
|
|
|
mockCheckOutput.return_value = b''
|
|
|
|
|
|
|
|
mockClone.side_effect = [
|
|
|
|
|
|
|
|
gclient_scm.subprocess2.CalledProcessError(
|
|
|
|
|
|
|
|
None, None, None, None, None),
|
|
|
|
|
|
|
|
None,
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
gclient_scm.os.path.isdir(
|
|
|
|
options = self.Options()
|
|
|
|
os.path.join(self.base_path, '.git', 'hooks')).AndReturn(False)
|
|
|
|
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
|
|
|
|
gclient_scm.os.path.exists(self.backup_base_path).AndReturn(False)
|
|
|
|
|
|
|
|
gclient_scm.os.path.exists(self.base_path).AndReturn(True)
|
|
|
|
|
|
|
|
gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
|
|
|
|
|
|
|
|
gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
|
|
|
|
|
|
|
|
).AndReturn(False)
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
|
|
|
|
|
|
|
|
# pylint: disable=no-value-for-parameter
|
|
|
|
|
|
|
|
gclient_scm.GitWrapper._Clone(
|
|
|
|
|
|
|
|
'refs/remotes/origin/master', self.url, options
|
|
|
|
|
|
|
|
).AndRaise(gclient_scm.subprocess2.CalledProcessError(None, None, None,
|
|
|
|
|
|
|
|
None, None))
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_DeleteOrMove', True)
|
|
|
|
|
|
|
|
gclient_scm.GitWrapper._DeleteOrMove(False)
|
|
|
|
|
|
|
|
gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
|
|
|
|
|
|
|
|
options)
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
|
|
|
|
|
|
|
|
gclient_scm.subprocess2.check_output(
|
|
|
|
|
|
|
|
['git', '-c', 'core.quotePath=false', 'ls-files'], cwd=self.base_path,
|
|
|
|
|
|
|
|
env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('')
|
|
|
|
|
|
|
|
gclient_scm.subprocess2.check_output(
|
|
|
|
|
|
|
|
['git', 'rev-parse', '--verify', 'HEAD'],
|
|
|
|
|
|
|
|
cwd=self.base_path,
|
|
|
|
|
|
|
|
env=gclient_scm.scm.GIT.ApplyEnvVars({}),
|
|
|
|
|
|
|
|
stderr=-1,
|
|
|
|
|
|
|
|
).AndReturn('')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.ReplayAll()
|
|
|
|
|
|
|
|
scm = self._scm_wrapper(self.url, self.root_dir,
|
|
|
|
|
|
|
|
self.relpath)
|
|
|
|
self.relpath)
|
|
|
|
scm.update(options, None, [])
|
|
|
|
scm.update(options, None, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
env = gclient_scm.scm.GIT.ApplyEnvVars({})
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
|
|
|
mockCheckOutput.mock_calls,
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
mock.call(
|
|
|
|
|
|
|
|
['git', '-c', 'core.quotePath=false', 'ls-files'],
|
|
|
|
|
|
|
|
cwd=self.base_path, env=env, stderr=-1),
|
|
|
|
|
|
|
|
mock.call(
|
|
|
|
|
|
|
|
['git', 'rev-parse', '--verify', 'HEAD'],
|
|
|
|
|
|
|
|
cwd=self.base_path, env=env, stderr=-1),
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
mockClone.assert_called_with(
|
|
|
|
|
|
|
|
'refs/remotes/origin/master', self.url, options)
|
|
|
|
self.checkstdout('\n')
|
|
|
|
self.checkstdout('\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -784,11 +749,11 @@ class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEquals(file_list, expected_file_list)
|
|
|
|
self.assertEqual(file_list, expected_file_list)
|
|
|
|
self.assertEquals(scm.revinfo(options, (), None),
|
|
|
|
self.assertEqual(scm.revinfo(options, (), None),
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458')
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458')
|
|
|
|
# indicates detached HEAD
|
|
|
|
# indicates detached HEAD
|
|
|
|
self.assertEquals(self.getCurrentBranch(), None)
|
|
|
|
self.assertEqual(self.getCurrentBranch(), None)
|
|
|
|
self.checkInStdout(
|
|
|
|
self.checkInStdout(
|
|
|
|
'Checked out refs/remotes/origin/master to a detached HEAD')
|
|
|
|
'Checked out refs/remotes/origin/master to a detached HEAD')
|
|
|
|
|
|
|
|
|
|
|
@ -816,11 +781,11 @@ class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEquals(file_list, expected_file_list)
|
|
|
|
self.assertEqual(file_list, expected_file_list)
|
|
|
|
self.assertEquals(scm.revinfo(options, (), None),
|
|
|
|
self.assertEqual(scm.revinfo(options, (), None),
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
'a7142dc9f0009350b96a11f372b6ea658592aa95')
|
|
|
|
# indicates detached HEAD
|
|
|
|
# indicates detached HEAD
|
|
|
|
self.assertEquals(self.getCurrentBranch(), None)
|
|
|
|
self.assertEqual(self.getCurrentBranch(), None)
|
|
|
|
self.checkInStdout(
|
|
|
|
self.checkInStdout(
|
|
|
|
'Checked out a7142dc9f0009350b96a11f372b6ea658592aa95 to a detached HEAD')
|
|
|
|
'Checked out a7142dc9f0009350b96a11f372b6ea658592aa95 to a detached HEAD')
|
|
|
|
|
|
|
|
|
|
|
@ -848,11 +813,11 @@ class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEquals(file_list, expected_file_list)
|
|
|
|
self.assertEqual(file_list, expected_file_list)
|
|
|
|
self.assertEquals(scm.revinfo(options, (), None),
|
|
|
|
self.assertEqual(scm.revinfo(options, (), None),
|
|
|
|
'9a51244740b25fa2ded5252ca00a3178d3f665a9')
|
|
|
|
'9a51244740b25fa2ded5252ca00a3178d3f665a9')
|
|
|
|
# indicates detached HEAD
|
|
|
|
# indicates detached HEAD
|
|
|
|
self.assertEquals(self.getCurrentBranch(), None)
|
|
|
|
self.assertEqual(self.getCurrentBranch(), None)
|
|
|
|
self.checkInStdout(
|
|
|
|
self.checkInStdout(
|
|
|
|
'Checked out 9a51244740b25fa2ded5252ca00a3178d3f665a9 '
|
|
|
|
'Checked out 9a51244740b25fa2ded5252ca00a3178d3f665a9 '
|
|
|
|
'to a detached HEAD')
|
|
|
|
'to a detached HEAD')
|
|
|
@ -881,11 +846,11 @@ class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEquals(file_list, expected_file_list)
|
|
|
|
self.assertEqual(file_list, expected_file_list)
|
|
|
|
self.assertEquals(scm.revinfo(options, (), None),
|
|
|
|
self.assertEqual(scm.revinfo(options, (), None),
|
|
|
|
'9a51244740b25fa2ded5252ca00a3178d3f665a9')
|
|
|
|
'9a51244740b25fa2ded5252ca00a3178d3f665a9')
|
|
|
|
# indicates detached HEAD
|
|
|
|
# indicates detached HEAD
|
|
|
|
self.assertEquals(self.getCurrentBranch(), None)
|
|
|
|
self.assertEqual(self.getCurrentBranch(), None)
|
|
|
|
self.checkInStdout(
|
|
|
|
self.checkInStdout(
|
|
|
|
'Checked out refs/remotes/origin/feature to a detached HEAD')
|
|
|
|
'Checked out refs/remotes/origin/feature to a detached HEAD')
|
|
|
|
|
|
|
|
|
|
|
@ -913,9 +878,9 @@ class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEquals(file_list, expected_file_list)
|
|
|
|
self.assertEqual(file_list, expected_file_list)
|
|
|
|
self.assertEquals(scm.revinfo(options, (), None),
|
|
|
|
self.assertEqual(scm.revinfo(options, (), None),
|
|
|
|
'9a51244740b25fa2ded5252ca00a3178d3f665a9')
|
|
|
|
'9a51244740b25fa2ded5252ca00a3178d3f665a9')
|
|
|
|
# @refs/heads/feature is AKA @refs/remotes/origin/feature in the clone, so
|
|
|
|
# @refs/heads/feature is AKA @refs/remotes/origin/feature in the clone, so
|
|
|
|
# should be treated as such by gclient.
|
|
|
|
# should be treated as such by gclient.
|
|
|
|
# TODO(mmoss): Though really, we should only allow DEPS to specify branches
|
|
|
|
# TODO(mmoss): Though really, we should only allow DEPS to specify branches
|
|
|
@ -924,7 +889,7 @@ class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
# defaults at some point). But that will take more work to stop using
|
|
|
|
# defaults at some point). But that will take more work to stop using
|
|
|
|
# refs/remotes/ everywhere that we do (and to stop assuming a DEPS ref will
|
|
|
|
# refs/remotes/ everywhere that we do (and to stop assuming a DEPS ref will
|
|
|
|
# always resolve locally, like when passing them to show-ref or rev-list).
|
|
|
|
# always resolve locally, like when passing them to show-ref or rev-list).
|
|
|
|
self.assertEquals(self.getCurrentBranch(), None)
|
|
|
|
self.assertEqual(self.getCurrentBranch(), None)
|
|
|
|
self.checkInStdout(
|
|
|
|
self.checkInStdout(
|
|
|
|
'Checked out refs/remotes/origin/feature to a detached HEAD')
|
|
|
|
'Checked out refs/remotes/origin/feature to a detached HEAD')
|
|
|
|
|
|
|
|
|
|
|
@ -940,19 +905,18 @@ class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
|
|
|
file_list = []
|
|
|
|
file_list = []
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
options.revision = 'unmanaged'
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
scm.update(options, (), file_list)
|
|
|
|
self.assertEquals(file_list, expected_file_list)
|
|
|
|
self.assertEqual(file_list, expected_file_list)
|
|
|
|
self.assertEquals(scm.revinfo(options, (), None),
|
|
|
|
self.assertEqual(scm.revinfo(options, (), None),
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458')
|
|
|
|
'069c602044c5388d2d15c3f875b057c852003458')
|
|
|
|
self.checkstdout('________ unmanaged solution; skipping .\n')
|
|
|
|
self.checkstdout('________ unmanaged solution; skipping .\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CipdWrapperTestCase(BaseTestCase):
|
|
|
|
class CipdWrapperTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
def setUp(self):
|
|
|
|
# Create this before setting up mocks.
|
|
|
|
# Create this before setting up mocks.
|
|
|
|
self._cipd_root_dir = tempfile.mkdtemp()
|
|
|
|
self._cipd_root_dir = tempfile.mkdtemp()
|
|
|
|
self._workdir = tempfile.mkdtemp()
|
|
|
|
self._workdir = tempfile.mkdtemp()
|
|
|
|
BaseTestCase.setUp(self)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._cipd_instance_url = 'https://chrome-infra-packages.appspot.com'
|
|
|
|
self._cipd_instance_url = 'https://chrome-infra-packages.appspot.com'
|
|
|
|
self._cipd_root = gclient_scm.CipdRoot(
|
|
|
|
self._cipd_root = gclient_scm.CipdRoot(
|
|
|
@ -963,12 +927,13 @@ class CipdWrapperTestCase(BaseTestCase):
|
|
|
|
self._cipd_root.add_package('b', 'bar_package', 'bar_version'),
|
|
|
|
self._cipd_root.add_package('b', 'bar_package', 'bar_version'),
|
|
|
|
self._cipd_root.add_package('b', 'baz_package', 'baz_version'),
|
|
|
|
self._cipd_root.add_package('b', 'baz_package', 'baz_version'),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
self.mox.StubOutWithMock(self._cipd_root, 'add_package')
|
|
|
|
mock.patch('tempfile.mkdtemp', lambda: self._workdir).start()
|
|
|
|
self.mox.StubOutWithMock(self._cipd_root, 'clobber')
|
|
|
|
mock.patch('gclient_scm.CipdRoot.add_package').start()
|
|
|
|
self.mox.StubOutWithMock(self._cipd_root, 'ensure')
|
|
|
|
mock.patch('gclient_scm.CipdRoot.clobber').start()
|
|
|
|
|
|
|
|
mock.patch('gclient_scm.CipdRoot.ensure').start()
|
|
|
|
|
|
|
|
self.addCleanup(mock.patch.stopall)
|
|
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
def tearDown(self):
|
|
|
|
BaseTestCase.tearDown(self)
|
|
|
|
|
|
|
|
rmtree(self._cipd_root_dir)
|
|
|
|
rmtree(self._cipd_root_dir)
|
|
|
|
rmtree(self._workdir)
|
|
|
|
rmtree(self._workdir)
|
|
|
|
|
|
|
|
|
|
|
@ -989,14 +954,12 @@ class CipdWrapperTestCase(BaseTestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def testRevert(self):
|
|
|
|
def testRevert(self):
|
|
|
|
"""Checks that revert does nothing."""
|
|
|
|
"""Checks that revert does nothing."""
|
|
|
|
scm = self.createScmWithPackageThatSatisfies(
|
|
|
|
scm = self.createScmWithPackageThatSatisfies(lambda _: True)
|
|
|
|
lambda _: True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.ReplayAll()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scm.revert(None, (), [])
|
|
|
|
scm.revert(None, (), [])
|
|
|
|
|
|
|
|
|
|
|
|
def testRevinfo(self):
|
|
|
|
@mock.patch('gclient_scm.gclient_utils.CheckCallAndFilter')
|
|
|
|
|
|
|
|
@mock.patch('gclient_scm.gclient_utils.rmtree')
|
|
|
|
|
|
|
|
def testRevinfo(self, mockRmtree, mockCheckCallAndFilter):
|
|
|
|
"""Checks that revinfo uses the JSON from cipd describe."""
|
|
|
|
"""Checks that revinfo uses the JSON from cipd describe."""
|
|
|
|
scm = self.createScmWithPackageThatSatisfies(lambda _: True)
|
|
|
|
scm = self.createScmWithPackageThatSatisfies(lambda _: True)
|
|
|
|
|
|
|
|
|
|
|
@ -1012,31 +975,20 @@ class CipdWrapperTestCase(BaseTestCase):
|
|
|
|
with open(describe_json_path, 'w') as describe_json:
|
|
|
|
with open(describe_json_path, 'w') as describe_json:
|
|
|
|
json.dump(json_contents, describe_json)
|
|
|
|
json.dump(json_contents, describe_json)
|
|
|
|
|
|
|
|
|
|
|
|
cmd = [
|
|
|
|
revinfo = scm.revinfo(None, (), [])
|
|
|
|
|
|
|
|
self.assertEqual(revinfo, expected_revinfo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mockRmtree.assert_called_with(self._workdir)
|
|
|
|
|
|
|
|
mockCheckCallAndFilter.assert_called_with([
|
|
|
|
'cipd', 'describe', 'foo_package',
|
|
|
|
'cipd', 'describe', 'foo_package',
|
|
|
|
'-log-level', 'error',
|
|
|
|
'-log-level', 'error',
|
|
|
|
'-version', 'foo_version',
|
|
|
|
'-version', 'foo_version',
|
|
|
|
'-json-output', describe_json_path,
|
|
|
|
'-json-output', describe_json_path,
|
|
|
|
]
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.StubOutWithMock(tempfile, 'mkdtemp')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tempfile.mkdtemp().AndReturn(self._workdir)
|
|
|
|
|
|
|
|
gclient_scm.gclient_utils.CheckCallAndFilter(cmd)
|
|
|
|
|
|
|
|
gclient_scm.gclient_utils.rmtree(self._workdir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.ReplayAll()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
revinfo = scm.revinfo(None, (), [])
|
|
|
|
|
|
|
|
self.assertEquals(revinfo, expected_revinfo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testUpdate(self):
|
|
|
|
def testUpdate(self):
|
|
|
|
"""Checks that update does nothing."""
|
|
|
|
"""Checks that update does nothing."""
|
|
|
|
scm = self.createScmWithPackageThatSatisfies(
|
|
|
|
scm = self.createScmWithPackageThatSatisfies(lambda _: True)
|
|
|
|
lambda _: True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.mox.ReplayAll()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scm.update(None, (), [])
|
|
|
|
scm.update(None, (), [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1327,7 +1279,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
|
|
|
|
self.url, 'refs/changes/36/1236/1', 'refs/heads/master', self.options,
|
|
|
|
self.url, 'refs/changes/36/1236/1', 'refs/heads/master', self.options,
|
|
|
|
file_list)
|
|
|
|
file_list)
|
|
|
|
self.assertEqual(cm.exception.cmd[:2], ['git', 'cherry-pick'])
|
|
|
|
self.assertEqual(cm.exception.cmd[:2], ['git', 'cherry-pick'])
|
|
|
|
self.assertIn('error: could not apply', cm.exception.stderr)
|
|
|
|
self.assertIn(b'error: could not apply', cm.exception.stderr)
|
|
|
|
|
|
|
|
|
|
|
|
# Try to apply 'refs/changes/35/1235/1', which doesn't have a merge
|
|
|
|
# Try to apply 'refs/changes/35/1235/1', which doesn't have a merge
|
|
|
|
# conflict.
|
|
|
|
# conflict.
|
|
|
|