【问题标题】:Commit message file missing in commit-msg hookcommit-msg 挂钩中缺少提交消息文件
【发布时间】:2020-05-11 06:24:56
【问题描述】:

我正在尝试编写一个 commit-msg 钩子来格式化我的提交消息以包装在最大列宽:

#!/bin/bash

format_max_column_width() {
  MAX_LINE_LENGTH_CHARS=50

  cat "$1" | grep -v "^Bug: |^Change-Id: |^Signed-off-by: |^CC: " > body
  cat "$1" | grep "^Bug: |^Change-Id: |^Signed-off-by: |^CC: " > footer
  fmt -w "$MAX_LINE_LENGTH_CHARS" body > body
  cat body > "$1"
  cat footer >> "$1"
  rm body footer
}

format_max_column_width

由于某种原因,当我提交时,我收到以下错误,因为 $1 似乎是空的。

cat: '': No such file or directory
cat: '': No such file or directory
.git/hooks/commit-msg: line 9: : No such file or directory
.git/hooks/commit-msg: line 10: : No such file or directory

此外,如果我只是echo $1,则不会打印任何内容,从而证实了这一理论。怎么回事?

【问题讨论】:

    标签: bash git githooks pre-commit-hook commit-message


    【解决方案1】:

    在 shell 函数中 $1 表示“函数的第一个参数”,而不是脚本。您需要将第一个脚本参数进一步传递给函数:

    format_max_column_width "$1"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 2013-10-16
      • 2020-12-11
      • 2015-03-09
      • 2010-12-23
      • 2015-05-21
      相关资源
      最近更新 更多