一次性git post-receive hook和多次提交

时间:2015-05-28 09:19:24

标签: git githooks git-post-receive

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

我的post-receive钩子,显然这只是用于测试:

#!/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%

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

我是否从根本上误解了接收后挂钩的工作方式?

1 个答案:

答案 0 :(得分:3)

您获得旧的和新的参考值,因此如果添加了多次提交,您通常可以使用$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