# Buggy code
def run_cmd(cwd, cmd):
    logger.debug('Executing "{}"'.format(" ".join(cmd)))
    if len(cmd) == 0:
        raise dbt.exceptions.CommandError(cwd, cmd)

    try:
        proc = subprocess.Popen(
            cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )

        out, err = proc.communicate()
    except OSError as exc:
        _interpret_oserror(exc, cwd, cmd)

    logger.debug('STDOUT: "{}"'.format(out))
    logger.debug('STDERR: "{}"'.format(err))

    if proc.returncode != 0:
        logger.debug("command return code={}".format(proc.returncode))
        raise dbt.exceptions.CommandResultError(cwd, cmd, proc.returncode, out, err)

    return out, err


# Traceback (AttributeError)
analytics-core git:(master) 1M 2A ₹ LC_ALL=es_ES dbt deps
Encountered an error:
'NoneType' object has no attribute 'group'
Traceback (most recent call last):
File "/Users/vijay/.pyenv/versions/3.6.5/lib/python3.6/site-packages/dbt/main.py", line 76, in main
results, succeeded = handle_and_check(args)
File "/Users/vijay/.pyenv/versions/3.6.5/lib/python3.6/site-packages/dbt/main.py", line 126, in handle_and_check
task, res = run_from_args(parsed)
File "/Users/vijay/.pyenv/versions/3.6.5/lib/python3.6/site-packages/dbt/main.py", line 181, in run_from_args
results = run_from_task(task, cfg, parsed)
File "/Users/vijay/.pyenv/versions/3.6.5/lib/python3.6/site-packages/dbt/main.py", line 189, in run_from_task
result = task.run()
File "/Users/vijay/.pyenv/versions/3.6.5/lib/python3.6/site-packages/dbt/task/deps.py", line 439, in run
target_config = final_deps[name].fetch_metadata(self.config)
File "/Users/vijay/.pyenv/versions/3.6.5/lib/python3.6/site-packages/dbt/task/deps.py", line 83, in fetch_metadata
self._cached_metadata = self._fetch_metadata(project)
File "/Users/vijay/.pyenv/versions/3.6.5/lib/python3.6/site-packages/dbt/task/deps.py", line 239, in _fetch_metadata
path = self._checkout(project)
File "/Users/vijay/.pyenv/versions/3.6.5/lib/python3.6/site-packages/dbt/task/deps.py", line 235, in _checkout
dirname=self._checkout_name)
File "/Users/vijay/.pyenv/versions/3.6.5/lib/python3.6/site-packages/dbt/clients/git.py", line 77, in clone_and_checkout
directory = matches.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

# Fixed code
def run_cmd(cwd, cmd, env=None):
    logger.debug('Executing "{}"'.format(" ".join(cmd)))
    if len(cmd) == 0:
        raise dbt.exceptions.CommandError(cwd, cmd)

    # the env argument replaces the environment entirely, which has exciting
    # consequences on Windows! Do an update instead.
    full_env = env
    if env is not None:
        full_env = os.environ.copy()
        full_env.update(env)

    try:
        proc = subprocess.Popen(
            cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=full_env
        )

        out, err = proc.communicate()
    except OSError as exc:
        _interpret_oserror(exc, cwd, cmd)

    logger.debug('STDOUT: "{}"'.format(out))
    logger.debug('STDERR: "{}"'.format(err))

    if proc.returncode != 0:
        logger.debug("command return code={}".format(proc.returncode))
        raise dbt.exceptions.CommandResultError(cwd, cmd, proc.returncode, out, err)

    return out, err