Skip to content
  • Junio C Hamano's avatar
    get_short_sha1(): correctly disambiguate type-limited abbreviation · 94d75d1e
    Junio C Hamano authored
    
    
    One test in t1512 that expects a failure incorrectly passed.  The
    test prepares a commit whose object name begins with ten "0"s, and
    also prepares a tag that points at the commit.  The object name of
    the tag also begins with ten "0"s.  There is no other commit-ish
    object in the repository whose name begins with such a prefix.
    
    Ideally, in such a repository:
    
        $ git rev-parse --verify 0000000000^{commit}
    
    should yield that commit.  If 0000000000 is taken as the commit
    0000000000e4f, peeling it to a commmit yields that commit itself,
    and if 0000000000 is taken as the tag 0000000000f8f, peeling it to a
    commit also yields the same commit, so in that twisted sense, the
    extended SHA-1 expression 0000000000^{commit} is unambigous.  The
    test that expects a failure is to check the above command.
    
    The reason the test expects a failure is that we did not implement
    such a "unification" of two candidate objects.  What we did (or at
    least, meant to) implement was to recognise that a commit-ish is
    required to expand 0000000000, and notice that there are two succh
    commit-ish, and diagnose the request as ambiguous.
    
    However, there was a bug in the logic to check the candidate
    objects.  When the code saw 0000000000f8f (a tag) that shared the
    shortened prefix (ten "0"s), it tried to make sure that the tag is a
    commit-ish by looking at the tag object.  Because it incorrectly
    used lookup_object() when the tag has not been parsed, however, we
    incorrectly declared that the tag is _not_ a commit-ish, leaving the
    sole commit in the repository, 0000000000e4f, that has the required
    prefix as "unique match", causing the test to pass when it shouldn't.
    
    This fixes the logic to inspect the type of the object a tag refers
    to, to make the test that is expected to fail correctly fail.
    
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    94d75d1e