Commit 979fa780 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

depot_tools: Make gclient_scm Python 3 compatible.

Bug: 984182
Change-Id: Ib9c5d2762546f29eaca5eae89b0428431067da4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1753029
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
parent 4ec0fe31
......@@ -448,7 +448,7 @@ class GitWrapper(SCMWrapper):
target_rev, patch_rev, base_rev))
self.Print('Current dir is %r' % self.checkout_path)
self.Print('git returned non-zero exit status %s:\n%s' % (
e.returncode, e.stderr))
e.returncode, e.stderr.decode('utf-8')))
# Print the current status so that developers know what changes caused
# the patch failure, since git cherry-pick doesn't show that
# information.
......@@ -553,7 +553,7 @@ class GitWrapper(SCMWrapper):
files = self._Capture(
['-c', 'core.quotePath=false', 'ls-files']).splitlines()
file_list.extend(
[os.path.join(self.checkout_path, f.decode()) for f in files])
[os.path.join(self.checkout_path, f) for f in files])
if mirror:
self._Capture(
['remote', 'set-url', '--push', 'origin', mirror.url])
......@@ -761,7 +761,8 @@ class GitWrapper(SCMWrapper):
merge_output = self._Capture(merge_args)
except subprocess2.CalledProcessError as e:
rebase_files = []
if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr):
if re.match(b'fatal: Not possible to fast-forward, aborting.',
e.stderr):
if not printed_path:
self.Print('_____ %s at %s' % (self.relpath, revision),
timestamp=False)
......@@ -791,19 +792,19 @@ class GitWrapper(SCMWrapper):
return
else:
self.Print('Input not recognized')
elif re.match("error: Your local changes to '.*' would be "
"overwritten by merge. Aborting.\nPlease, commit your "
"changes or stash them before you can merge.\n",
elif re.match(b"error: Your local changes to '.*' would be "
b"overwritten by merge. Aborting.\nPlease, commit your "
b"changes or stash them before you can merge.\n",
e.stderr):
if not printed_path:
self.Print('_____ %s at %s' % (self.relpath, revision),
timestamp=False)
printed_path = True
raise gclient_utils.Error(e.stderr)
raise gclient_utils.Error(e.stderr.decode('utf-8'))
else:
# Some other problem happened with the merge
logging.error("Error during fast-forward merge in %s!" % self.relpath)
self.Print(e.stderr)
self.Print(e.stderr.decode('utf-8'))
raise
else:
# Fast-forward merge was successful
......@@ -1117,8 +1118,8 @@ class GitWrapper(SCMWrapper):
try:
rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path)
except subprocess2.CalledProcessError as e:
if (re.match(r'cannot rebase: you have unstaged changes', e.stderr) or
re.match(r'cannot rebase: your index contains uncommitted changes',
if (re.match(br'cannot rebase: you have unstaged changes', e.stderr) or
re.match(br'cannot rebase: your index contains uncommitted changes',
e.stderr)):
while True:
rebase_action = self._AskForData(
......@@ -1136,18 +1137,19 @@ class GitWrapper(SCMWrapper):
"cd %s && git " % self.checkout_path
+ "%s" % ' '.join(rebase_cmd))
elif re.match(r'show|s', rebase_action, re.I):
self.Print('%s' % e.stderr.strip())
self.Print('%s' % e.stderr.decode('utf-8').strip())
continue
else:
gclient_utils.Error("Input not recognized")
continue
elif re.search(r'^CONFLICT', e.stdout, re.M):
elif re.search(br'^CONFLICT', e.stdout, re.M):
raise gclient_utils.Error("Conflict while rebasing this branch.\n"
"Fix the conflict and run gclient again.\n"
"See 'man git-rebase' for details.\n")
else:
self.Print(e.stdout.strip())
self.Print('Rebase produced error output:\n%s' % e.stderr.strip())
self.Print(e.stdout.decode('utf-8').strip())
self.Print('Rebase produced error output:\n%s' %
e.stderr.decode('utf-8').strip())
raise gclient_utils.Error("Unrecognized error, please merge or rebase "
"manually.\ncd %s && git " %
self.checkout_path
......@@ -1177,7 +1179,7 @@ class GitWrapper(SCMWrapper):
try:
self._Capture(['rev-list', '-n', '1', 'HEAD'])
except subprocess2.CalledProcessError as e:
if ('fatal: bad object HEAD' in e.stderr
if (b'fatal: bad object HEAD' in e.stderr
and self.cache_dir and self.cache_dir in url):
self.Print((
'Likely due to DEPS change with git cache_dir, '
......
......@@ -980,7 +980,7 @@ class FakeReposTestBase(trial_dir.TestCase):
def gitrevparse(self, repo):
"""Returns the actual revision for a given repo."""
return self.FAKE_REPOS._git_rev_parse(repo)
return self.FAKE_REPOS._git_rev_parse(repo).decode('utf-8')
def main(argv):
......
......@@ -79,9 +79,6 @@ class TestCaseUtils(object):
self.args = self.Args()
self.relpath = self.String(200)
def tearDown(self):
pass
class StdoutCheck(object):
def setUp(self):
......@@ -130,7 +127,6 @@ class SuperMoxTestBase(TestCaseUtils, StdoutCheck, mox.MoxTestBase):
def tearDown(self):
StdoutCheck.tearDown(self)
TestCaseUtils.tearDown(self)
mox.MoxTestBase.tearDown(self)
def MockList(self, parent, items_to_mock):
......
This diff is collapsed.
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