Skip to content
  • brian m. carlson's avatar
    http-push: ensure unforced pushes fail when data would be lost · 64472d15
    brian m. carlson authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    When we push using the DAV-based protocol, the client is the one that
    performs the ref updates and therefore makes the checks to see whether
    an unforced push should be allowed.  We make this check by determining
    if either (a) we lack the object file for the old value of the ref or
    (b) the new value of the ref is not newer than the old value, and in
    either case, reject the push.
    
    However, the ref_newer function, which performs this latter check, has
    an odd behavior due to the reuse of certain object flags.  Specifically,
    it will incorrectly return false in its first invocation and then
    correctly return true on a subsequent invocation.  This occurs because
    the object flags used by http-push.c are the same as those used by
    commit-reach.c, which implements ref_newer, and one piece of code
    misinterprets the flags set by the other.
    
    Note that this does not occur in all cases.  For example, if the example
    used in the tests is changed to use one repository instead of two and
    rewind the head to add a commit, the test passes and we correctly reject
    the push.  However, the example provided does trigger this behavior, and
    the code has been broken in this way since at least Git 2.0.0.
    
    To solve this problem, let's move the two sets of object flags so that
    they don't overlap, since we're clearly using them at the same time.
    The new set should not conflict with other usage because other users are
    either builtin code (which is not compiled into git http-push) or
    upload-pack (which we similarly do not use here).
    
    Reported-by: default avatarMichael Ward <mward@smartsoftwareinc.com>
    Signed-off-by: default avatarRené Scharfe <l.s.r@web.de>
    Signed-off-by: default avatarbrian m. carlson <sandals@crustytoothpaste.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    64472d15