安裝git-format-staged後,Sourcetree中提交程式碼報錯的解決方案

夏风已过發表於2024-08-17

pre-commit檔案中內容為:

git-format-staged --formatter "swiftformat stdin --stdinpath '{}'" "*.swift"

在終端中,git commit不會報錯。Sourcetree中提交具體錯誤:

git-format-staged或者swiftformat命令找不到。

解決方案一:

利用Automator(自動操作)新建一個SourceTree應用程式。

export PATH=/usr/local/bin:/opt/homebrew/bin/:$PATH
open -a Sourcetree

儲存之後即可。

拖動icon,修改新建的app icon

方案二:

將pre-commit中命令修改為:

/usr/local/bin/git-format-staged --formatter "/opt/homebrew/bin/swiftformat stdin --stdinpath '{}'" "*.swift"

相關文章