Skip to main content

git_policy_cli/
rule_commit_only_message.rs

1//! What:
2//!  The user-facing diagnostics of the commit-only transform.
3//! Why:
4//!  Each message names the rejected form and every valid way forward;
5//!  keeping the text
6//!      apart from the decision keeps both files readable.
7//!
8//! In TS you'd write (pseudocode):
9//! ```ts
10//! // const NO_PATHSPEC_MESSAGE = 'cli-git: git commit requires an explicit pathspec ...';
11//! ```
12
13/// Diagnostic for a commit with no pathspec source and no mode that permits a pathless
14/// only-commit.
15pub const NO_PATHSPEC_MESSAGE: &str = "cli-git: git commit requires an explicit pathspec when commit-only enforcement is active. \
16Name the paths in the commit command (for example, git commit -m <msg> <path>), \
17pass --pathspec-from-file, pass --no-only to commit the entire index, \
18or pass --no-enforce-only to bypass for this invocation.";
19
20/// Diagnostic for `-a`/`--all`,
21///  which stages tracked modifications implicitly.
22pub const ALL_FLAG_MESSAGE: &str = "cli-git: git commit rejects -a/--all because it stages every tracked modification before committing. \
23Stage paths explicitly and commit with git commit -m <msg> <path>, \
24or pass --no-enforce-only to bypass for this invocation.";
25
26/// What:
27///  Build the diagnostic for a pathless `--amend`/`--allow-empty` commit over a dirty
28///       index.
29///  `&str` borrows the flag text;
30///  `String` is the owned result.
31/// Why:
32///   An injected `--only` would commit `HEAD`'s existing tree and leave the staged
33///       changes staged without any warning from Git.
34///
35/// In TS you'd write (pseudocode):
36/// ```ts
37/// function ignoredIndexMessage(flagText: string): string;
38/// ```
39pub fn ignored_index_message(flag_text: &str) -> String {
40    // `format!` builds an owned `String`; `{flag_text}` inserts the borrowed text.
41    return format!(
42        "cli-git: git commit {flag_text} without pathspecs would silently ignore your staged changes. \
43Commit-only enforcement injects --only, and a pathless --only commit reuses HEAD's existing tree, \
44leaving staged changes staged with no warning; the index currently differs from HEAD. \
45Choose explicitly: name the paths to include them (git commit --amend <path>), \
46pass --only to proceed without them, \
47or pass --no-only to commit the entire index."
48    );
49}