def get_sha1_or_none(repo, ref):
    """Return string of the ref's commit hash if valid, else None.

    :repo: a callable supporting git commands, e.g. repo("status")
    :ref: string of the reference to parse
    :returns: string of the ref's commit hash if valid, else None.

    """
    commit = repo("rev-parse", "--revs-only", ref).strip()
    return commit if commit else None