git_rewrite/lib.rs
1//! Porcelain for rewriting Git repository history and trees.
2//!
3//! `git-rewrite` wraps the [`git-filter-tree`](https://docs.rs/git-filter-tree)
4//! plumbing library in a user-friendly `git`-style CLI. It operates on the
5//! working tree's index so results are immediately staged and ready to commit.
6//!
7//! # CLI
8//!
9//! ```text
10//! git rewrite tree [--only <PATTERN>]... [<TREEISH>]
11//! ```
12//!
13//! Keep only Rust source files from `HEAD`, staged into the index:
14//!
15//! ```text
16//! git rewrite tree --only '**/*.rs'
17//! ```
18//!
19//! Rewrite a specific commit, keeping two directories:
20//!
21//! ```text
22//! git rewrite tree abc1234 --only 'src/' --only 'tests/'
23//! ```
24//!
25//! By default the working tree must be clean. Pass `--allow-dirty` to skip
26//! that check.
27//!
28//! # Library
29//!
30//! [`exe::tree`] is the programmatic entry point. It opens a repository from
31//! the environment, filters the given tree-ish by glob patterns, and rewrites
32//! the index:
33//!
34//! ```no_run
35//! use git_rewrite::exe;
36//! use git_rewrite::TreeArgs;
37//!
38//! let args = TreeArgs {
39//! treeish: "HEAD".into(),
40//! patterns: vec!["**/*.rs".into()],
41//! allow_dirty: false,
42//! };
43//! exe::tree(&args)?;
44//! # Ok::<(), Box<dyn std::error::Error>>(())
45//! ```
46
47pub mod exe;
48
49pub use exe::TreeArgs;