git_iris/commit/
mod.rs

1mod cli;
2mod relevance;
3
4pub mod prompt;
5pub mod service;
6
7pub use cli::handle_gen_command;
8use git2::FileMode;
9pub use service::IrisCommitService;
10
11use crate::git::CommitResult;
12
13pub fn format_commit_result(result: &CommitResult, message: &str) -> String {
14    let mut output = format!(
15        "[{} {}] {}\n",
16        result.branch,
17        result.commit_hash,
18        message.lines().next().unwrap_or("")
19    );
20
21    output.push_str(&format!(
22        " {} file{} changed, {} insertion{}(+), {} deletion{}(-)\n",
23        result.files_changed,
24        if result.files_changed == 1 { "" } else { "s" },
25        result.insertions,
26        if result.insertions == 1 { "" } else { "s" },
27        result.deletions,
28        if result.deletions == 1 { "" } else { "s" }
29    ));
30
31    for (file, mode) in &result.new_files {
32        output.push_str(&format!(
33            " create mode {} {}\n",
34            format_file_mode(*mode),
35            file
36        ));
37    }
38
39    output
40}
41
42fn format_file_mode(mode: FileMode) -> String {
43    match mode {
44        FileMode::Blob => "100644",
45        FileMode::BlobExecutable => "100755",
46        FileMode::Link => "120000",
47        FileMode::Commit => "160000",
48        FileMode::Tree => "040000",
49        _ => "000000",
50    }
51    .to_string()
52}