def get_remote_branches_list(remote):
    """Gets a list of branches and hashes for a given remote.

    Args:
        remote: String containing the specific remote.

    Returns:
        Dictionary with each key as a branch name and the value for the key
            the hash (as a string) of HEAD in that branch.

    Raises:
        GitRvException: If the output of ls-remote is unexpected, such as a
            commit hash value that is 40 hex characters, a row that isn't two
            tab delimited fields, or a head that doesn't start with refs/heads/.
    """
    branches_output = capture_command('git', 'ls-remote', '--heads',
                                      remote, single_line=False)

    split_branches = [line.split('\t') for line in branches_output.split('\n')]

    branches = {}
    for split in split_branches:
        if len(split) != 2:
            bad_content = '\n'.join([
                repr('\t'.join(split)),
                '',
                'Expected two tab-delimited fields.',
            ])
            error_msg = LS_REMOTE_ERROR_TEMPLATE % (bad_content,)
            raise GitRvException(error_msg)

        commit_hash, head_ref = split
        try:
            _check_hash(commit_hash)
        except GitRvException, exc:  # Syntax for python<2.6
            bad_content = exc.message
            error_msg = LS_REMOTE_ERROR_TEMPLATE % (bad_content,)
            raise GitRvException(error_msg)

        if not head_ref.startswith('refs/heads/'):
            bad_content = ('Head reference %r does not begin with '
                           'refs/heads.' % (head_ref,))
            error_msg = LS_REMOTE_ERROR_TEMPLATE % (bad_content,)
            raise GitRvException(error_msg)

        branch = head_ref.split('refs/heads/', 1)[1]
        branches[branch] = commit_hash

    return branches
dataset/ETHPy150Open googlearchive/git-rv/utils.py/get_remote_branches_list/original