vcs-modify-guard
Help CLI tools decide whether it is safe to modify files in a VCS working tree.
vcs-modify-guard helps CLI tools enforce --allow-dirty,
--allow-staged, and --allow-no-vcs style checks before they modify
files.
Currently, this crate supports Git repositories. Backend selection is controlled by Cargo features; see Feature flags.
API overview
This crate provides two layers of API:
AllowOptionsis the main entry point. It implementscargo fix-style safe-to-modify checks and returns aModificationSafetydescribing whether modification is safe. By default, checks are scoped to the queried path.repository::Repositoryis a lower-level API for tools that need to discover a repository and inspect whether files are dirty and/or staged to implement their own policy. Dirty files include modified tracked files and untracked files.
Most users should start with AllowOptions. Reach for
repository::Repository only when you need custom behavior beyond the
built-in --allow-* semantics.
Feature flags
This crate currently supports Git repositories via selectable Git backends.
Backend selection features
git-default(enabled by default) enables the default Git backend. Currently, this enablesgit-gix.git-gixenables thegixbackend.git-libgit2enables thelibgit2backend.git-clienables the Git CLI backend.
To opt out of the default backend, disable default features and enable the desired backend feature(s) explicitly:
[]
= {
version = "0.1.0",
= false,
= ["git-libgit2"]
}
If multiple backends are enabled, they are tried in this fixed priority
order: gix, then libgit2, then the Git CLI.
If no backend selection features are enabled, repository discovery reports that no supported repository was found.
Backend configuration features
vendored-libgit2forwards togit2’svendored-libgit2feature whengit-libgit2is enabled.
Example
The following example shows how to validate whether a target path is safe to modify before performing an operation that may modify files.
use ;
use Parser;
use ;
See the allow_options example for a complete command-line application.
If you need custom policy logic instead of the built-in --allow-*
behavior, see the repository module for direct repository discovery and
change query APIs.
Minimum supported Rust version (MSRV)
The minimum supported Rust version is Rust 1.96.0.
While a crate is a pre-release status (0.x.x) it may have its MSRV bumped in a patch release. Once a crate has reached 1.x, any MSRV bump will be accompanied by a new minor version.
License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
See CONTRIBUTING.md.