#pre-commit #git-hook #yaml #shell #git-commit #task #file

app commitment

简化你的Git预提交钩子

7个版本

0.2.3 2023年6月22日
0.2.2 2023年6月21日
0.1.2 2023年6月19日

#9 in #pre-commit

每月38次下载

GPL-3.0或更高版

310KB
413

承诺

Crates.io Crates.io

Commitment Example

简化你的Git预提交钩子。

用法

警告

承诺文件包含任意shell命令。在安装承诺文件时请谨慎,并且始终先进行审查!

要使用承诺,首先在你的项目根目录中创建一个 commitment.yml 文件。下一节提供了一个示例。

承诺文件必须在生效前安装。要在项目根目录中安装承诺文件,请运行 commitment install

示例承诺文件

# Tasks are defined below. They run sequentially. If one fails, the following
# tasks are skipped and Commitment returns an error code.
 
cargo-build:
  # You can specify file globs to determine what should be restaged after the
  # task has succeeded. File globs can be specific file paths or patterns such
  # as `*.rs` or `docs/**/*.md`.
  restage:
    # If this is false, only files that were previously staged will be restaged.
    # Otherwise any file, wether staged or not will be staged after the task
    # has succeeded.
    allow-any: true
    globs:
      - Cargo.toml
      - Cargo.lock

  # This must be defined for every task. Multiple commands can be specified and
  # will be executed within the same shell session. This means you can change
  # directories and run commands there.
  execute:
    - cargo build --color=always

cargo-fmt:
  # When present, files with the matching extension will be restaged before
  # the commit is made. In this case, it's used to auto-format the code before
  # each commit.
  restage:
    extensions: ["rs"]
  execute:
    - cargo fmt

cargo-clippy:
  execute:
    - cargo clippy --color=always -- -D warnings

cargo-audit:
  # Setting this to true will allow following tasks to continue and won't reject
  # the commit.
  can-fail: true
  execute:
    - cargo audit

输出

当承诺执行一个文件时,每个任务及其中的命令都会被输出。对于命令本身,stdoutstderr 将在命令运行时显示,并带有行号。红色标记的行号表示该行来自 stderr

所有任务执行完毕后,结果将如下显示

╔═══════════════════════════╗
║          RESULTS          ║
╚═══════════════════════════╝

 cargo-build....................SUCCESS
   cargo-fmt....................SUCCESS
cargo-clippy....................SUCCESS
 cargo-audit....................SKIPPED

PASSED: 3/4 (75.00%)

可能的状态有

状态 描述
SUCCESS 任务完成,没有错误
FAILURE 任务未能完成
SKIPPED 任务失败,但 can-fail 被设置为 true
IGNORED 之前的任务已失败,此任务未运行

依赖项

~5–17MB
~182K SLoC