'Remove a refname only if it currently equals old_ref.
This method does not follow symbolic references. It can be used to
perform an atomic compare-and-delete operation.
:param name: The refname to delete.
:param old_ref: The old sha the refname must refer to, or None to
delete unconditionally.
:return: True if the delete was successful, False otherwise.'

def remove_if_equals(self, name, old_ref):

    self._check_refname(name)
    filename = self.refpath(name)
    ensure_dir_exists(os.path.dirname(filename))
    f = GitFile(filename, 'wb')
    try:
        if (old_ref is not None):
            orig_ref = self.read_loose_ref(name)
            if (orig_ref is None):
                orig_ref = self.get_packed_refs().get(name, ZERO_SHA)
            if (orig_ref != old_ref):
                return False
        try:
            os.remove(filename)
        except OSError as e:
            if (e.errno != errno.ENOENT):
                raise
        self._remove_packed_ref(name)
    finally:
        f.abort()
    return True
