Return Git active branch, state, branches (plus tags).

def get_git_refs(repopath):
    """
    Return Git active branch, state, branches (plus tags).
    """
    tags = []
    branches = []
    branch = ''
    files_modifed = []

    if os.path.isfile(repopath):
        repopath = os.path.dirname(repopath)

    try:

        git = programs.find_program('git')

        # Files modified
        out, err = programs.run_program(
            git, ['status', '-s'],
            cwd=repopath,
        ).communicate()

        if PY3:
            out = out.decode(sys.getdefaultencoding())
        files_modifed = [line.strip() for line in out.split('\n') if line]

        # Tags
        out, err = programs.run_program(
            git, ['tag'],
            cwd=repopath,
        ).communicate()

        if PY3:
            out = out.decode(sys.getdefaultencoding())
        tags = [line.strip() for line in out.split('\n') if line]

        # Branches
        out, err = programs.run_program(
            git, ['branch', '-a'],
            cwd=repopath,
        ).communicate()

        if PY3:
            out = out.decode(sys.getdefaultencoding())

        lines = [line.strip() for line in out.split('\n') if line]
        for line in lines:
            if line.startswith('*'):
                line = line.replace('*', '').strip()
                branch = line

            branches.append(line)

    except (subprocess.CalledProcessError, AttributeError, OSError):
        pass

    return branches + tags, branch, files_modifed