Git receive/update hooks and new branches

前端 未结 4 889
一生所求
一生所求 2020-12-05 17:28

I have a problem with the \'update\' hook. In the case of a new branch, it gets a 0000000000000000000000000000000000000000 as the \'oldrev\'. And I don\'t know how to handle

4条回答
  •  渐次进展
    2020-12-05 18:17

    The term "right answer" is a bit ambiguous in this case. I actually think that "all revs reachable from newrev but nowhere else" is completely correct. This is true even if there was a merge - in that case, you should see the commits unique to the new ref, and the merge commit, but not the commits that were merged.

    So, I would say, check if the "oldrev" is all zeroes, and if it is, act accordingly:

    if [ "$oldrev" -eq 0 ]; then
        # list everything reachable from newrev but not any heads
        git rev-list $(git for-each-ref --format='%(refname)' refs/heads/* | sed 's/^/\^/') "$newrev"
    else
        git rev-list "$oldrev..$newrev"
    fi
    

提交回复
热议问题