commitizen / commitizen/cz-cli

Git-generated trailers are not preserved

未关闭
#820 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
17.5k
派生
566
平均合并
8 小时 16 分钟
30 天内合并 PR
1

描述

Commitizen's `--hook` option truncates the `COMMIT_EDITMSG` file. This wipes the `Signed-off-by` trailer generated by Git's `-s` flag, as well as any other trailers that might have been there before running Commitizen, and forces us to amend our commits after the fact.

We have a temporary workaround in our hook for this, which might offer some insight:

```sh
#!/bin/bash

file="$1"
type="$2"

if [ -z "$type" ]; then # only run on new commits
#
# Save any commit message trailers generated by Git.
#

trailers=$(git interpret-trailers --parse "$file")

#
# Execute the Commitizen hook.
#

(exec < "/dev/tty" && npx --no-install git-cz --hook) || true

#
# Restore any trailers that Commitizen might have overwritten.
#

printf "\n" >> "$file"

while IFS= read -r trailer; do
git interpret-trailers --in-place --trailer "$trailer" "$file"
done <<< "$trailers"
fi
```

Version: cz-cli@4.2.2, cz-conventional-changelog@3.3.0

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。