Back to directory
csjones avatar
csjones / lefthook-plugin

lefthook-plugin

Fast and powerful Git hooks manager for Swift packages.

11

Stars

0

Forks

2

Watchers

MIT

License

lefthook-plugin

A Swift Package that integrates lefthook, a fast and powerful Git hooks manager, into the Swift ecosystem.

Features

  • Fast Execution: Written in Go, lefthook can run commands in parallel.
  • Powerful Configuration: Control execution and the files you pass to your commands.
  • Swift Integration: Seamlessly integrates with Swift projects through the Swift Package Manager.
  • Mint support: Run lefthook using mint, a package manager for Swift CLI tools.

Installation

Using Swift Package Manager plugin

To utilize the lefthook-plugin, include it in the target specification of your Swift Package:

// swift-tools-version: 5.6
import PackageDescription

let package = Package(
    name: "YourPackageName",
    dependencies: [
        .package(url: "https://github.com/csjones/lefthook-plugin.git", exact: "2.1.10"),
    ],
    targets: [
        .executableTarget(name: "YourTargetName")
    ]
)

This configuration ensures that SPM invokes the plugin, thereby integrating lefthook's capabilities into your Swift project.

Using mint

$ mint install csjones/lefthook-plugin

Commands

After lefthook is installed in your Swift project, it's time to run it.

Using Swift Package Manager plugin

Invoke the plugin directly using the swift package plugin CLI:

swift package lefthook --help

Run lefthook install to initialize a lefthook.yml config and/or synchronize .git/hooks/ with your configuration.

swift package --disable-sandbox lefthook install

[!IMPORTANT]
The lefthook plugin necessitates the --disable-sandbox flag with the Swift Package Manager due to its requirement for local document access to read files.

To execute the lefthook plugin within your package repository:

swift package --disable-sandbox lefthook run pre-commit

[!NOTE] For a detailed understanding of lefthook's commands and their usage, refer to lefthook's official usage documentation.

Using mint

After running mint install csjones/lefthook-plugin to install the CLI tool, anytime you want to interact with lefthook, all you have to do is run mint run csjones/lefthook-plugin <command>. Example: mint run csjones/lefthook-plugin --help.

Configuration

Below is a sample configuration for lefthook:

pre-push:
  commands:
    1_test:
      run: swift test

pre-commit:
  commands:
    1_swiftformat:
      glob: "*.{swift}"
      run: swift run swiftformat --config .swiftformat {all_files}
    2_swiftlint:
      glob: "*.{swift}"
      run: swift run swiftlint --autocorrect --strict --no-cache
    3_git:
      run: git add .

[!TIP] For a comprehensive understanding and more advanced configurations, refer to lefthook's official configuration documentation.

Community and Support

If you encounter any issues or have questions regarding the lefthook-plugin, please open an issue on GitHub. Contributions, suggestions, and feedback are always welcome!

Acknowledgments

Special thanks to the original lefthook project and its contributors for creating a powerful Git hooks manager.

Releases

Changelog

c0a32e900407bf3e2e97c99a7dd2e3f2864ba13a deps: July 2026 (#1463) 0b87ca6dc643dab804a1aad59c24003ef147c11a deps: June 2026 (#1447) afce7244cf02abaf996ebe87bb557a725e46993e deps: migrate shel...

May 29, 2026

Download .zip

Changelog

1d35cbabe1ebaf2a5ed4d2186caa0402de6448e2 chore: add pretty gradient (#1432) 22be6c50e1412c748f3c6b60e9c61cd056dc693b deps: May 2026 (#1415) 1bae568f03dfb88af9185031fa44e9fee285e917 fix: upd...

May 19, 2026

Download .zip

Changelog

488a5f99a5a496e5837f757f8ce3e6c6d1415792 fix: do not warn if local hooks path is equal to default hooks path (#1421)

May 19, 2026

Download .zip

Changelog

f415a9d3fce1d4f6af62622cf96c72e04ecf7bd3 chore: go mod tidy cf4ab9ea4580f5aeb0d4b61d4dd169533e5bb0c9 fix: always restore unstaged changes (#1416) 4c0e000d6fe9f35f42efefb9263b0b4cb5dfbd49 fi...

Apr 16, 2026

Download .zip

Changelog

bf73ea2f1ea5468c9af7a6f06b5ef8cd43e66040 fix(packaging): do not pipe stdout and stderr (#1382) 04da00697cd8a6241023c1962feb720eeaa62698 fix(windows): normalize lefthook path for sh script (...