How to get ALL hashes that are being committed in a pre-receive hook?

为君一笑 提交于 2019-11-30 15:47:16
VonC

You can use a pre-receive hook and still list all pushed commits.
See this answer which includes:

chomp(my @commits = `git rev-list $old..$new`);
if ($?) {
  warn "git rev-list $old..$new failed\n";
  ++$errors, next;
}

foreach my $sha1 (@commits) {
  // validate some policy
}

As commented by torek, this is only for the master branch.

You can deal with multiple branches:

#!/bin/bash
while read oldrev newrev refname
do
    branch=$(git rev-parse --symbolic --abbrev-ref $refname)
    if [ "master" == "$branch" ]; then
        # Do something
    fi
done
while read old new ref; do 
    [[ $new = *[^0]* ]] && news="$news $new"
done
git rev-list $news --not --all

This will avoid things like fastforwards over previously-pushed commits triggering wasted revalidation of unchanged content.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!