Skip to main content

gitkraft_gui/features/remotes/
update.rs

1//! Update logic for remote-related messages.
2
3use iced::Task;
4
5use crate::message::Message;
6use crate::state::GitKraft;
7
8use super::commands;
9
10/// Handle all remote-related messages, returning a [`Task`] for any follow-up
11/// async work.
12pub fn update(state: &mut GitKraft, message: Message) -> Task<Message> {
13    match message {
14        Message::Fetch => {
15            // Resolve the remote name before entering the macro so it can be
16            // used in both the status string and the command argument.
17            let remote_name = state
18                .active_tab()
19                .remotes
20                .first()
21                .map(|r| r.name.clone())
22                .unwrap_or_else(|| "origin".to_string());
23
24            with_repo!(
25                state,
26                loading,
27                format!("Fetching from '{remote_name}'…"),
28                |repo_path| commands::fetch_remote(repo_path, remote_name)
29            )
30        }
31
32        Message::FetchCompleted(result) => {
33            state.on_ok_refresh(result, "Fetch completed.", "Fetch failed")
34        }
35
36        _ => Task::none(),
37    }
38}