# Buggy code
def parse(root):
    l = do("hg id -i -t", root).split()
    node = l.pop(0)
    tags = tags_to_versions(l)
    # filter tip in degraded mode on old setuptools
    tags = [x for x in tags if x != "tip"]
    dirty = node[-1] == "+"
    if tags:
        return meta(tags[0], dirty=dirty)

    if node.strip("+") == "0" * 12:
        trace("initial node", root)
        return meta("0.0", dirty=dirty)

    # the newline is needed for merge stae, see issue 72
    cmd = 'hg parents --template "{latesttag} {latesttagdistance}\n"'
    out = do(cmd, root)
    try:
        # in merge state we assume parent 1 is fine
        tags, dist = out.splitlines()[0].split()
        # pick latest tag from tag list
        tag = tags.split(":")[-1]
        if tag == "null":
            tag = "0.0"
            dist = int(dist) + 1
        return _hg_tagdist_normalize_tagcommit(root, tag, dist, node)
    except ValueError:
        pass  # unpacking failed, old hg


# Traceback (FileNotFoundError)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-qg_odikh-build/setup.py", line 234, in <module>
zip_safe=False)
File "/usr/lib/python3.5/distutils/core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "/appenv/lib/python3.5/site-packages/setuptools/dist.py", line 272, in __init__
_Distribution.__init__(self,attrs)
File "/usr/lib/python3.5/distutils/dist.py", line 281, in __init__
self.finalize_options()
File "/appenv/lib/python3.5/site-packages/setuptools/dist.py", line 327, in finalize_options
ep.load()(self, ep.name, value)
File "/tmp/pip-qg_odikh-build/.eggs/setuptools_scm-1.10.1-py3.5.egg/setuptools_scm/integration.py", line 19, in version_keyword
File "/tmp/pip-qg_odikh-build/.eggs/setuptools_scm-1.10.1-py3.5.egg/setuptools_scm/__init__.py", line 102, in get_version
File "/tmp/pip-qg_odikh-build/.eggs/setuptools_scm-1.10.1-py3.5.egg/setuptools_scm/__init__.py", line 69, in _do_parse
File "/tmp/pip-qg_odikh-build/.eggs/setuptools_scm-1.10.1-py3.5.egg/setuptools_scm/__init__.py", line 30, in version_from_scm
File "/tmp/pip-qg_odikh-build/.eggs/setuptools_scm-1.10.1-py3.5.egg/setuptools_scm/__init__.py", line 36, in _version_from_entrypoint
File "/tmp/pip-qg_odikh-build/.eggs/setuptools_scm-1.10.1-py3.5.egg/setuptools_scm/git.py", line 11, in parse
File "/tmp/pip-qg_odikh-build/.eggs/setuptools_scm-1.10.1-py3.5.egg/setuptools_scm/utils.py", line 58, in do_ex
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1541, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'git'

# Fixed code
def parse(root):
    if not has_command("hg"):
        return
    l = do("hg id -i -t", root).split()
    node = l.pop(0)
    tags = tags_to_versions(l)
    # filter tip in degraded mode on old setuptools
    tags = [x for x in tags if x != "tip"]
    dirty = node[-1] == "+"
    if tags:
        return meta(tags[0], dirty=dirty)

    if node.strip("+") == "0" * 12:
        trace("initial node", root)
        return meta("0.0", dirty=dirty)

    # the newline is needed for merge stae, see issue 72
    cmd = 'hg parents --template "{latesttag} {latesttagdistance}\n"'
    out = do(cmd, root)
    try:
        # in merge state we assume parent 1 is fine
        tags, dist = out.splitlines()[0].split()
        # pick latest tag from tag list
        tag = tags.split(":")[-1]
        if tag == "null":
            tag = "0.0"
            dist = int(dist) + 1
        return _hg_tagdist_normalize_tagcommit(root, tag, dist, node)
    except ValueError:
        pass  # unpacking failed, old hg