lefthook

1.11.13

Fast and powerful Git hooks manager for Swift packages.
csjones/lefthook-plugin

What's New

2025-05-16T08:30:26Z

Changelog

  • 5876b5f704c7951cf22b2e71248a6d4ebfc983b4 chore: change "existed" to "exisiting" (#1022)
  • 4c95a2adeca3c351a233629087fdbbe1912133e8 chore: help text for install command
  • 4ef67a93a07c3df36e616c04fc7ef2ce03169715 deps: May 2025 (#1024)
  • 406e3a3561f674f9ca14062e12a92bd67d9b226d fix: load scripts from .config too (#1018)

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: "1.11.13"),
    ],
    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.

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon May 19 2025 22:41:06 GMT-0900 (Hawaii-Aleutian Daylight Time)