'Add a new reference only if it does not already exist.
This method follows symrefs, and only ensures that the last ref in the
chain does not exist.
:param name: The refname to set.
:param ref: The new sha the refname will refer to.
:return: True if the add was successful, False otherwise.'

def add_if_new(self, name, ref):

    try:
        (realnames, contents) = self.follow(name)
        if (contents is not None):
            return False
        realname = realnames[(-1)]
    except (KeyError, IndexError):
        realname = name
    self._check_refname(realname)
    filename = self.refpath(realname)
    ensure_dir_exists(os.path.dirname(filename))
    with GitFile(filename, 'wb') as f:
        if (os.path.exists(filename) or (name in self.get_packed_refs())):
            f.abort()
            return False
        try:
            f.write((ref + '\n'))
        except (OSError, IOError):
            f.abort()
            raise
    return True
