【问题标题】:git: how to grep received files in pre-receive hookgit:如何在预接收挂钩中 grep 接收到的文件
【发布时间】:2020-09-07 17:22:55
【问题描述】:

我在本地存储库.git/hooks/ 中创建了以下预推送脚本,以禁止将具有未解决的 git 冲突的文件推送到服务器:

#!/bin/bash
top_dir=$(git rev-parse --show-toplevel)
conflicts=$(grep -r -n -s --include=\*.{pm,pl,mc,mi,js,css} "<<<<<<< HEAD" "$top_dir")

if [ "$conflicts" = "" ]; then
    exit 0
else
    printf "Unresolved git conflict found, commit rejected.\n\n"
    echo "$conflicts"
    exit 1
fi

它有效。但是我们如何才能拒绝所有在服务器端pre-receive 上存在未解决冲突的提交呢?在这里,我知道top_dir - 目录,在哪里 grep。但是在服务器上没有保存的文件。我需要在客户端发送给我的文件中进行 grep。

怎么做?

【问题讨论】:

  • 你为什么问the same question两次?
  • @dan1st(我认为这是第一个)---(我还假设其他人正在使用他们的帐户)
  • 根据时间戳,这是第二个。根据ids,这是第一个
  • 哦,他删了。
  • 推送的引用被发送到 pre-receive 钩子上的stdin

标签: git


【解决方案1】:

作为“pre-receive hook unable to read the committed file to push into remote master”中的torek文档:

预接收钩子通常更难编写,因为您必须处理许多情况:

  • 多次提交
  • 不是分支(标签)的引用
  • 不是提交的对象(带注释的标签)
  • 分支创建和删除以及更新

那种钩子works well for commit messages.
话虽如此,您可以看到an example here,在名义情况下:

# <oldrev> <newrev> <refname>
while  read oldrev newrev ref ;
do
    list = $ ( git show --pretty = " format: " --name-only $ {newrev}  | grep -e ' .php ' -e ' .phtml ' )
    for  file  in  $ {list} ;  do
        git show $ {newrev} : $ {file}  >  $ TMP_FILE
        OUTPUT = $ ( $ PHPCS_BIN -s --standard = $ PHPCS_CODING_STANDARD  $ TMP_FILE )
        ...

【讨论】:

    猜你喜欢
    • 2012-01-03
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多