Skip to main content

gitkraft_gui/features/commits/
commands.rs

1//! Async command helpers for commit operations.
2//!
3//! Each function spawns blocking work on a background thread via the
4//! `git_task!` macro, performs the git operation, and maps the result into a
5//! [`Message`].
6
7use std::path::PathBuf;
8
9use iced::Task;
10
11use crate::message::Message;
12
13/// Load just the file list (paths + statuses) for a commit — no line parsing.
14pub fn load_commit_file_list(path: PathBuf, oid: String) -> Task<Message> {
15    git_task!(
16        Message::CommitFileListLoaded,
17        (|| {
18            let repo = open_repo!(&path);
19            gitkraft_core::features::diff::get_commit_file_list(&repo, &oid)
20                .map_err(|e| e.to_string())
21        })()
22    )
23}
24
25/// Load the full diff for a single file in a commit.
26pub fn load_single_file_diff(path: PathBuf, oid: String, file_path: String) -> Task<Message> {
27    git_task!(
28        Message::SingleFileDiffLoaded,
29        (|| {
30            let repo = open_repo!(&path);
31            gitkraft_core::features::diff::get_single_file_diff(&repo, &oid, &file_path)
32                .map_err(|e| e.to_string())
33        })()
34    )
35}
36
37/// Create a new commit with the currently staged changes.
38pub fn create_commit(path: PathBuf, message: String) -> Task<Message> {
39    git_task!(
40        Message::CommitCreated,
41        (|| {
42            let repo = open_repo!(&path);
43            gitkraft_core::features::commits::create_commit(&repo, &message)
44                .map(|_| ())
45                .map_err(|e| e.to_string())
46        })()
47    )
48}