#git-hook #git #git-repository #team #attempt #members #teamwork

app git-hooks-manager

尝试使团队成员之间共享 git 钩(hooks)更容易

6 个版本

0.4.2 2020 年 12 月 13 日
0.4.1 2020 年 12 月 13 日
0.3.0 2020 年 12 月 11 日
0.2.3 2020 年 12 月 11 日

#1416 in 开发工具

自定义许可证

42KB
902

Git 钩管理器

Paul Ollivier [email protected]

本项目试图提供一种方便地共享 git 钩 的方法。

在许多团队中,我们依赖于一套完整的工具,并且需要共享代码约定和质量标准。

此工具试图通过众所周知的共享仓库 dotfiles 机制统一 git 钩管理。

安装

最新版本页面 下载一份副本,使用 chmod +x 修改权限,并将其放置在您的 $PATH 中的一个目录下。推荐使用 ~/.local/bin 吗?

或者,如果您有 cargo:cargo install git-hooks-manager。在这种情况下,二进制文件将位于 ~/.cargo/bin

用法

.git-hooks 二进制帮助页面 [源码]

$ git-hooks --help
git-hooks
Paul Ollivier <[email protected]>
A git hooks manager

USAGE:
    git-hooks [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    help           Prints this message or the help of the given subcommand(s)
    init           Install the git hooks in .git/hooks
    run            Runs the configured hooks for a given event
    self-update    git-hooks will try to update itself.

如果您正在启动一个新项目,或者至少在一个新项目上尝试 git-hooks,您应该运行 git-hooks init。这将设置项目以在 git 事件上运行 git-hooks

如果您想手动运行钩子集合,可以调用 git-hooks run <event>

.git-hooks "run" 命令的帮助文本 [源码,shell]

git-hooks-run
Runs the configured hooks for a given event

USAGE:
    git-hooks run <event>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <event>    Runs the hook for the given event, eg. "pre-commit", "post-commit"[possible values: apply-patch-
               msg, commit-msg, post-commit, post-update, pre-apply-patch, pre-commit, pre-merge-commit,
               pre-push, pre-rebase, pre-receive, prepare-commit-msg, update]

使用和编写钩子

这部分内容在 其自己的页面 上进行了说明。

设计文档

我相信 Rust 是系统工具的最佳语言,因为它的性能和错误处理设计。

此解决方案包含 3 个部分

  • 仓库内的配置文件,指定为每个人启用哪个钩子,以及钩子来源。
  • 包含设置和使用各种工具的代码的多个钩子代码库。例如,一个 rust 代码库可能包含 rustfmtcargo check 或甚至 cargo test 钩子的定义。
  • 与您现在阅读的文档一起提供的二进制文件。此二进制文件需要处理读取存储库的配置文件、下载钩子存储库,并将它们应用于适当的 Git 事件(pre-commitpost-commit 等)。

.hooks.yml 文件

此文件预计位于 Git 存储库的根目录。它包含主二进制文件要读取的定义。

rust 项目示例文件 [source,yaml]

repos:
  - https://github.com/paulollivier/rust-hooks
hooks:
  - name: cargofmt

钩子定义存储库

这是一个简单的 Git 存储库,其根目录包含一个 hooks.yml

[警告]

不要与 .hooks.yml 混淆!带点的版本用于当前存储库的 Git 钩子管理器,不带点的版本用于钩子定义!

包含钩子定义的示例文件 [source,yaml]

hooks:
  - name: rustfmt
    on_event:
      - pre-commit
    on_file_regex:
      - "*.rs"
    action: "rustfmt {files}"
    setup_script: rustfmt_setup.sh

示例存储库结构 [source]

.
|-- hooks.yml
`-- rustfmt_setup.sh

git-hooks 二进制文件

角色

  • 管理钩子存储库
  • 克隆钩子存储库
  • 拉取存储库
  • 检出特定的钩子存储库版本
  • 初始化钩子存储库(执行其设置脚本)
  • .hooks.yml 钩子部分如果设置则覆盖 hooks.yml 定义
  • 设置为在 Git 事件上执行
  • (部分实现) 处理多个参数,例如 {file}{files}{root}{changed_files}
  • 限制执行到指定的文件正则表达式
  • 仅在 Git 索引包含指定的文件正则表达式时运行
  • 实现自更新

依赖关系

~15–30MB
~496K SLoC