git post-一次推送接收钩子和多次提交

git post-receive hook and multiple commits in one push

我试图了解当多个提交被推到一起时 git post-receive 挂钩中会发生什么。从我看到的文档和示例来看,我希望它接受来自 STDIN 的引用列表,允许我对每个单独的提交采取行动,但它似乎不是那样工作的?这是我拥有的:

我的post-receive hook,显然这只是为了测试:

#!/usr/bin/perl

use Data::Dumper;
my @input = <STDIN>;    
print STDERR Dumper(\@input);

我编辑了两个文件,分别提交:

nelson% git log origin/master..HEAD
commit 93f96201f2cfd3e83a9a609ec644dc873aefeb17
Author: cecukemon <cecukemon@...>
Date:   Thu May 28 11:09:19 2015 +0200

    commit 2

commit 8bbcc8370101d44c8a7302fb365f257e62a61e9d
Author: cecukemon <cecukemon@...>
Date:   Thu May 28 11:09:09 2015 +0200

    commit 1

将它们作为一个推送:

nelson% git push
Counting objects: 6, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 542 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: $VAR1 = [
remote:           'fa45b972bb59fbe92d7331cfad5d2933a53414ce 93f96201f2cfd3e83a9a609ec644dc873aefeb17 refs/heads/master
remote: '
remote:         ];
To /home/cecukemon/hooktest
   fa45b97..93f9620  master -> master

两个提交都已成功推送:

nelson% git log origin/master..HEAD
nelson%

并且 post-receive 挂钩已成功执行,但我只在引用列表中看到其中一个提交(推送输出中的 $VAR1)。

我是否从根本上误解了 post-接收挂钩的工作原理?

你得到旧的和新的 ref 值,所以如果添加了多个提交,你通常可以用 $old..$new 得到它们(例如传递给 git rev-list)。

while read old new ref; do
        while read commit; do
                # check the commit here
        done <<EOD
$(git rev-list $old..$new)
EOD