A tiny crate to make it easy to share and apply Git hooks for Rust projects

Overview

Sloughi

Crates.io Crates.io Crates.io

Sloughi Dog

A tiny crate to make it easy to share and apply Git hooks for Rust projects. Inspired by Husky.

  • Zero dependencies.
  • No magic, uses Git's config core.hooksPath to set a custom hooks path. Use native/regular shell scripts for git hooks.
  • Makes use of Cargo's build script.
  • IDE/Code editor agnostic.
  • Customizable setup.

Sloughi is an ancient breed of domesticated dog originating from North Africa (i.e. Algeria, where I live πŸ‘‹ ).

Install

  • Add sloughi to your build-dependencies (not dev-dependencies):

    [build-dependencies]
    sloughi = "0.3.0"
  • Create a build.rs file at the root of your project to install Sloughi (besides Cargo.toml, not inside src/):

    use sloughi::Sloughi;
    
    fn main() {
        let _ = Sloughi::new().install(); // This will fail silently. Won't interrupt the build.
    }

That's it!

The next time cargo build is triggered (by VSCode, or by running cargo run/cargo test), you will notice a .sloughi folder is created with a sample pre-commit hook inside.

Customizing the install

This crate uses the builder pattern, you can chain options on top ::new() to adjust the install:

let _ = Sloughi::new()
    .custom_path(".git_hooks").   // Choose a custom Git hooks relative path (default is ".sloughi")
    .ignore_env("CI").            // Ignore setup when `CI` environment variable is set (like in CircleCI ..etc)
    .ignore_env("GITHUB_ACTIONS") // Do not run in Github Actions as well
    .install();

Fail the build

The above snippets for build.rs will not interrupt the build in case Sloughi install failed (e.g. not a git repo, permission error ..etc). It's explicitly silenced with let _ =, you can handle the error however you like, or just yell with:

Sloughi::new().install().expect("Sloughi install failed");

F.A.Q

Why use build.rs?

Cargo lacks install hooks (like postinstall in npm's package.json), this makes it challenging to have a way to share git hooks automatically in a upstream repository.

Cargo's build script is a nice & transparent way to:

  • Act on the project at build/compile time.
  • Customize the setup without extra config files and formats.

What happens when cargo build is run multiple times?

The install() call is idempotent. It won't modify the existing setup and hooks.

Will this slow down my builds?

No:

  • build.rs itself is only built when it's changed (by default).
  • The setup will first check if you already have .sloughi (or the custom path) created. If so, it skips installs.

Does it run in release mode?

No, release mode is a no-op.

TODO:

  • Optional feature flags. I.e. conventional commits as pre-commit, rustfmt as pre-commit.
  • A [optiona] companion binary to manage hooks.
  • Check Cargo workspaces compatiblity.
  • Introduce the uninstall() call to the exported Sloughi struct.
  • Integration tests.
You might also like...
Attempt to make a git profile switcher to switch profiles.

Git Profile Switcher β–ˆβ–€β–€β€ƒβ–ˆβ€ƒβ–€β–ˆβ–€β€ƒ β€ƒβ–ˆβ–€β€ƒβ–ˆβ–‘β–ˆβ–‘β–ˆβ€ƒβ–ˆβ€ƒβ–€β–ˆβ–€β€ƒβ–ˆβ–€β–€β€ƒβ–ˆβ–‘β–ˆβ€ƒβ–ˆβ–€β–€β€ƒβ–ˆβ–€β–ˆ β–ˆβ–„β–ˆβ€ƒβ–ˆβ€ƒβ–‘β–ˆβ–‘β€ƒ β€ƒβ–„β–ˆβ€ƒβ–€β–„β–€β–„β–€β€ƒβ–ˆβ€ƒβ–‘β–ˆβ–‘β€ƒβ–ˆβ–„β–„β€ƒβ–ˆβ–€β–ˆ

A Cli to generate React Component and Hooks.

React Cli A cli to create React Components and Hooks. Instructions: Download the binary. To Create A React Component ./react -n Component Name T

A library and binary for testing unhooking ntdll by identifying hooks via in-memory disassembly
A library and binary for testing unhooking ntdll by identifying hooks via in-memory disassembly

(First Public?) Sample of unhooking ntdll (All Exports & IAT imports) hooks in Rust using in-memory disassembly, avoiding direct syscalls and all hooked functions (incl. hooked NtProtectVirtualMemory)

epNFTs, the first partial program-owned NFT Standard powered by Instruction Introspection and Transfer Hooks!

epNFT Standard: A Comprehensive Guide Introduction to epNFTs Welcome to the epNFT-standard repository, where we explore the first program-owned NFT st

Resize observer hooks for Dioxus 🧬

dioxus-resize-observer Resize observer hooks for Dioxus 🧬. Support 0.1.0 - Dioxus v0.4 🧬 git - Dioxus v0.5 Web renderer (WASM) Example use dioxus::p

Make data-driven table rendering easy with Dioxus

Dioxus Table Make data-driven table rendering easy with Dioxus Installation Until the next release of Dioxus this requires Dioxus nightly from git. Th

A gui tool written in Dioxus to make it easy to release a workspace of crates to crates.io
A gui tool written in Dioxus to make it easy to release a workspace of crates to crates.io

Easy-Release: a visual tool for releasing workspaces of libraries A work-in-progress GUI for releasing a large workspace of crates manually, but easil

Share clipboard between machines on your local network.

Clipshare Do you ever have to work on multiple machines? Do you ever used your Githubβ„’ Gists just to send some text between then? Clipshare is here to

A program to share a TTY like a GPS UART between 2 processes.

TTYTEE - A process that exposes 2 copies of the same TTY. The initial use case for this crate has been sharing a single GPS device talking through an

Releases(v0.3.0)
Owner
Walid ZIOUCHE
Software Engineer (mainly Python / TS / Golang)
Walid ZIOUCHE
Workflows make it easy to browse, search, execute and share commands (or a series of commands)--without needing to leave your terminal.

Workflows The repo for all public Workflows that appear within Warp and within commands.dev. To learn how to create local or repository workflows, see

Warp 369 Jan 2, 2023
Workflows make it easy to browse, search, execute and share commands (or a series of commands)--without needing to leave your terminal.

Workflows The repo for all public Workflows that appear within Warp and within commands.dev. To learn how to create local or repository workflows, see

Warp 227 Jun 1, 2022
Tiny Rust CLI to checkout a recent git branch interactively

git-select-branch Tiny Rust CLI to checkout a recent git branch interactively. Installation Homebrew brew tap dnjstrom/git-select-branch brew install

Daniel StrΓΆm 5 Oct 11, 2022
Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux.

Load Symbols Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux. Requirements Last tested wi

null 4 Jul 20, 2022
Just a collection of tiny Rust projects I've did. None warrant a whole repo rn

Daily Rust I try to write some tiny programs daily to gradually improve my Rust skills! Current Program Descriptions first_prog.rs: My first program a

null 3 Nov 5, 2022
A cli util to apply themes to hyprland

Hyprtheme works with themes installed at ~/.config/hypr/themes additional themes can be installed from hyprland-community/theme-repo theme.toml this f

Hyprland Community 4 Jan 15, 2023
A simple cli to clone projects and fetch all projects in a GitHub org..

stupid-git A simple cli to clone projects and update all projects. get all repository from GitHub clone all pull all with git stash Usage create sgit.

Fengda Huang 5 Sep 15, 2022
git-cliff can generate changelog files from the Git history by utilizing conventional commits as well as regex-powered custom parsers.⛰️

git-cliff can generate changelog files from the Git history by utilizing conventional commits as well as regex-powered custom parsers. The changelog template can be customized with a configuration file to match the desired format.

Orhun ParmaksΔ±z 5k Jan 9, 2023
A git sub-command to view your git repository in the web browser

git-view A git sub-command to view your git repository in the web browser! About Are you also frustrated from moving your hands away from the keyboard

Hamothy 5 Sep 26, 2022
Git Explorer: cross-platform git workflow improvement tool inspired by Magit

Gex Git workflow improvement CLI tool inspired by Magit. This project is still under initial development, but I am actively dogfooding it and features

Peter Hebden 204 Jan 6, 2023