【问题标题】:git filter-repo: run lint-history without stopping on errorsgit filter-repo:运行 lint-history 而不会因错误而停止
【发布时间】:2022-11-11 00:43:17
【问题描述】:

我正在使用与git-filter-repo 关联的lint-history 工具清理一个存储库,将 Prettier 应用于所有提交:

python lint-history --relevant 'filename.endswith(b".ts")' prettier -w

它设法处理了几百个提交,然后崩溃:

[error] ../../../../../var/abc123/somefile.ts: Expected valid tag name
[error]   30 |
[error]   31 |         <div>
[error] > 32 | <<<<<<< HEAD
[error]   33 |
Traceback (most recent call last):
  File "xyz/lint-history", line 174, in <module>
    filter.run()
  ...
  File "xyz/lint-history", line 132, in lint_with_real_filenames
    subprocess.check_call(lint_args.command + [filename.decode('utf-8')])
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['prettier', '-w', '/var/abc13/somefile.ts']' returned non-zero exit status 2.
fatal: stream ends early
fast-import: dumping crash report to .git/fast_import_crash_5034

看起来有问题的提交有一些当时没有解决的合并符号(&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD 等等)。我怎样才能让 Prettier 单独留下文件而不是退出并显示错误代码?或者,尽管来自 Prettier 的错误,我可以让lint-history 继续吗?

【问题讨论】:

    标签: prettier git-filter-repo


    【解决方案1】:

    我通过编写一个名为maybe-prettier 的脚本解决了这个问题:

    #! /usr/bin/env zsh
    
    # Prettier gives three exit codes:
    #  0 file is good
    #  1 needs formatting
    #  2 error
    
    # Check the file and get the exit code. If the file needs
    # formatting but doesn't produce an error, then format it.
    prettier -c $1
    if [[ $? = 1 ]]; then
      prettier -w $1
    fi
    

    然后我可以运行lint-history maybe-prettier。

    【讨论】:

      猜你喜欢
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      相关资源
      最近更新 更多