# Buggy code
def get_git_url(dockerfile_path):
    """Given a dockerfile_path, return url of git project which contains
    the dockerfile in a form of list."""
    # get the path of the folder containing the dockerfile
    dockerfile_folder_path = os.path.dirname(dockerfile_path)
    command = ["git", "remote", "-v"]
    try:
        output = subprocess.check_output(  # nosec
            command, stderr=subprocess.DEVNULL, cwd=dockerfile_folder_path
        )
        if isinstance(output, bytes):
            lines = output.decode("utf-8").split("\n")
            # pop the last line which is an empty line
            lines.pop()
            url_list = set()
            for line in lines:
                extract_url = extract_git_url_from_line(line)
                if extract_url:
                    url_list.add(extract_url)
    except subprocess.CalledProcessError:
        logger.debug("Cannot find git repo url, path is %s", dockerfile_folder_path)
    return url_list


# Traceback (FileNotFoundError)
Traceback (most recent call last):
File "/home/rjudge/ternenv/bin/tern", line 10, in <module>
sys.exit(main())
File "/home/rjudge/ternenv/tern/tern/__main__.py", line 201, in main
do_main(args)
File "/home/rjudge/ternenv/tern/tern/__main__.py", line 90, in do_main
run.execute_dockerfile(args)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/run.py", line 176, in execute_dockerfile
output = dockerfile.create_locked_dockerfile(dfobj)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/dockerfile.py", line 283, in create_locked_dockerfile
expand_add_command(dfobj)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/dockerfile.py", line 270, in expand_add_command
dockerfile_path)
File "/home/rjudge/ternenv/tern/tern/analyze/docker/dockerfile.py", line 256, in find_git_info
comment_line = common.check_git_src(dockerfile_path)
File "/home/rjudge/ternenv/tern/tern/analyze/common.py", line 536, in check_git_src
path_to_toplevel = get_git_toplevel(dockerfile_folder_path)
File "/home/rjudge/ternenv/tern/tern/analyze/common.py", line 618, in get_git_toplevel
command, stderr=subprocess.DEVNULL, cwd=path)
File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '': ''

# Fixed code
def get_git_url(dockerfile_path):
    """Given a dockerfile_path, return url of git project which contains
    the dockerfile in a form of list."""
    # get the path of the folder containing the dockerfile
    dockerfile_folder_path = os.path.dirname(os.path.abspath(dockerfile_path))
    command = ["git", "remote", "-v"]
    try:
        output = subprocess.check_output(  # nosec
            command, stderr=subprocess.DEVNULL, cwd=dockerfile_folder_path
        )
        if isinstance(output, bytes):
            lines = output.decode("utf-8").split("\n")
            # pop the last line which is an empty line
            lines.pop()
            url_list = set()
            for line in lines:
                extract_url = extract_git_url_from_line(line)
                if extract_url:
                    url_list.add(extract_url)
    except (subprocess.CalledProcessError, FileNotFoundError):
        logger.debug("Cannot find git repo url, path is %s", dockerfile_folder_path)
    return url_list