Shusky is a port of Husky to Swift which allow to execute
git hooks with Swift. Can prevent git commit and git push.
- Prevent, inter alia,
git commit,git push... - Configure commands as non-critical. It allow to keep going with
gitcommand execution. - Configure commands as non-verbose. (Maybe does not work for all comands).
- Skip git hooks with
SKIP_SHUSKY. For example:SKIP_SHUSKY=1 git commit -m. - Handle
swift runcommand for you.
Add the following code to your Package.swift file.
.package(url: "https://github.com/didix21/Shusky", from: "1.0.0")Then:
-
If you have your
Package.swiftfile in the root, run:swift run -c release shusky install
-
If you have your
Package.swiftfile to another path, run:swift build --package-path YourPath -c release --product shusky ./YourPath/.build/release/shusky install --package-path YourPath
This will add a new file .shusky.yml in your root with the following configuration:
pre-push:
- echo "Shusky is ready, please configure .shusky.yml"
pre-commit:
- echo "Shusky is ready, please configure .shusky.yml"
NOTE: Shusky installation is safe, it will not remove any previous content in your git hooks file. it only will add the command for running shusky. More info in Advanced installation.
-
Only need to add your commands in
.shusky.ymlconfiguration file. For example:pre-push: - set -o pipefail && swift test 2>&1 | xcpretty --color pre-commit: - swift run -c release swiftformat . - swift run -c release swiftlint lint . - git add -A
-
If you add a new hook you must run again
shusky install. For example:pre-push: - set -o pipefail && swift test 2>&1 | xcpretty --color pre-commit: - swift run -c release swiftformat . - swift run -c release swiftlint lint . - git add -A pre-merge-commit: - swift test
-
Maybe you want to run SPM binaries, but you always have to remember to run
swift runfor compiling the binary. Don't worry, usingswift-runoption, shusky will handle it for you.pre-commit: - swift-run: command: swiftformat .
-
You can add especial behaviour to commands using the key
run. For example you can set non-verbose to commands. Then only wil display output result only if the command fails. For example:pre-commit: - swift run -c release swiftformat . - swift run -c release swiftlint lint . - run: command: set -o pipefail && swift test 2>&1 | xcpretty --color verbose: false - git add -A
-
Maybe while you're developing you don't want to cancel the
git commitif one of the commands fail. So you can set propiertycriticaltofalse. In this example, ifswiftlintfails will keep going with the commit:pre-commit: - swift run -c release swiftformat . - run: command: swift run -c release swiftlint lint . critical: false - git add -A
NOTE: More info in Advanced configurations
Run:
swift run -c release shusky uninstall