Bug 1389366 - Fix |mach try| when hg is not installed. - r=ahal
Also find_executable doesn't seem to work on my windows machine, so I've replaced it.
MozReview-Commit-ID: 3mE4UeQ2ecy
--- a/tools/tryselect/vcs.py
+++ b/tools/tryselect/vcs.py
@@ -2,17 +2,16 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json
import os
import subprocess
import sys
from abc import ABCMeta, abstractmethod, abstractproperty
-from distutils.spawn import find_executable
GIT_CINNABAR_NOT_FOUND = """
Could not detect `git-cinnabar`.
The `mach try` command requires git-cinnabar to be installed when
pushing from git. For more information and installation instruction,
please see:
@@ -48,21 +47,22 @@ class VCSHelper(object):
def find_vcs(cls):
# First check if we're in an hg repo, if not try git
commands = (
['hg', 'root'],
['git', 'rev-parse', '--show-toplevel'],
)
for cmd in commands:
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- output = proc.communicate()[0].strip()
+ try:
+ output = subprocess.check_output(cmd).strip()
+ except (subprocess.CalledProcessError, OSError):
+ continue
- if proc.returncode == 0:
- return cmd[0], output
+ return cmd[0], output
return None, ''
@classmethod
def create(cls):
vcs, root = cls.find_vcs()
if not vcs:
print(VCS_NOT_FOUND)
sys.exit(1)
@@ -134,17 +134,19 @@ class HgHelper(VCSHelper):
return len(stat) > 0
class GitHelper(VCSHelper):
def push_to_try(self, msg, labels=None):
self.check_working_directory()
- if not find_executable('git-cinnabar'):
+ try:
+ subprocess.check_output(['git', 'cinnabar', '--version'], stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError:
print(GIT_CINNABAR_NOT_FOUND)
return 1
if labels:
config = self.write_task_config(labels)
self.run(['git', 'add', config])
subprocess.check_call(['git', 'commit', '--allow-empty', '-m', msg])