Skip to content
  • Junio C Hamano's avatar
    branch: correctly reject refs/heads/{-dash,HEAD} · a625b092
    Junio C Hamano authored
    
    
    strbuf_check_branch_ref() is the central place where many codepaths
    see if a proposed name is suitable for the name of a branch.  It was
    designed to allow us to get stricter than the check_refname_format()
    check used for refnames in general, and we already use it to reject
    a branch whose name begins with a '-'.  The function gets a strbuf
    and a string "name", and returns non-zero if the name is not
    appropriate as the name for a branch.  When the name is good, it
    places the full refname for the branch with the proposed name in the
    strbuf before it returns.
    
    However, it turns out that one caller looks at what is in the strbuf
    even when the function returns an error.  Make the function populate
    the strbuf even when it returns an error.  That way, when "-dash" is
    given as name, "refs/heads/-dash" is placed in the strbuf when
    returning an error to copy_or_rename_branch(), which notices that
    the user is trying to recover with "git branch -m -- -dash dash" to
    rename "-dash" to "dash".
    
    While at it, use the same mechanism to also reject "HEAD" as a
    branch name.
    
    Helped-by: default avatarJeff King <peff@peff.net>
    Helped-by: default avatarKaartic Sivaraam <kaartic.sivaraam@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    a625b092