From 3e1ad8215552f724098c8a766cbd853bf19953ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alen=20=C5=A0iljak?= Date: Wed, 21 Dec 2022 11:35:56 +0100 Subject: [PATCH 1/4] adding the command to Status view --- src/keys/key_list.rs | 2 ++ src/keys/key_list_file.rs | 2 ++ src/strings.rs | 11 +++++++++++ src/tabs/status.rs | 6 ++++++ 4 files changed, 21 insertions(+) diff --git a/src/keys/key_list.rs b/src/keys/key_list.rs index 24c66e959f..121056b6c6 100644 --- a/src/keys/key_list.rs +++ b/src/keys/key_list.rs @@ -103,6 +103,7 @@ pub struct KeysList { pub open_file_tree: GituiKeyEvent, pub file_find: GituiKeyEvent, pub force_push: GituiKeyEvent, + pub fetch: GituiKeyEvent, pub pull: GituiKeyEvent, pub abort_merge: GituiKeyEvent, pub undo_commit: GituiKeyEvent, @@ -184,6 +185,7 @@ impl Default for KeysList { push: GituiKeyEvent::new(KeyCode::Char('p'), KeyModifiers::empty()), force_push: GituiKeyEvent::new(KeyCode::Char('P'), KeyModifiers::SHIFT), undo_commit: GituiKeyEvent::new(KeyCode::Char('U'), KeyModifiers::SHIFT), + fetch: GituiKeyEvent::new(KeyCode::Char('F'), KeyModifiers::SHIFT), pull: GituiKeyEvent::new(KeyCode::Char('f'), KeyModifiers::empty()), abort_merge: GituiKeyEvent::new(KeyCode::Char('A'), KeyModifiers::SHIFT), open_file_tree: GituiKeyEvent::new(KeyCode::Char('F'), KeyModifiers::SHIFT), diff --git a/src/keys/key_list_file.rs b/src/keys/key_list_file.rs index 9ac19e4f3b..024ab89626 100644 --- a/src/keys/key_list_file.rs +++ b/src/keys/key_list_file.rs @@ -74,6 +74,7 @@ pub struct KeysListFile { pub open_file_tree: Option, pub file_find: Option, pub force_push: Option, + pub fetch: Option, pub pull: Option, pub abort_merge: Option, pub undo_commit: Option, @@ -165,6 +166,7 @@ impl KeysListFile { open_file_tree: self.open_file_tree.unwrap_or(default.open_file_tree), file_find: self.file_find.unwrap_or(default.file_find), force_push: self.force_push.unwrap_or(default.force_push), + fetch: self.fetch.unwrap_or(default.fetch), pull: self.pull.unwrap_or(default.pull), abort_merge: self.abort_merge.unwrap_or(default.abort_merge), undo_commit: self.undo_commit.unwrap_or(default.undo_commit), diff --git a/src/strings.rs b/src/strings.rs index c7cf5d79e5..d43a9f1346 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -1440,6 +1440,17 @@ pub mod commands { CMD_GROUP_GENERAL, ) } + + pub fn status_fetch(key_config: &SharedKeyConfig) -> CommandText { + CommandText::new( + format!( + "Fetch [{}]", + key_config.get_hint(key_config.keys.fetch), + ), + "fetch", + CMD_GROUP_GENERAL, + ) + } pub fn status_pull(key_config: &SharedKeyConfig) -> CommandText { CommandText::new( format!( diff --git a/src/tabs/status.rs b/src/tabs/status.rs index cd544b4b09..c27a062ffa 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -761,6 +761,12 @@ impl Component for Status { true, self.can_push() && !focus_on_diff, )); + + out.push(CommandInfo::new( + strings::commands::status_fetch(&self.key_config), + self.can_pull(), + !focus_on_diff, + )); out.push(CommandInfo::new( strings::commands::status_pull(&self.key_config), self.can_pull(), From 87246cce4c4a1f0fb8c6c56d31baa21741cd935f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alen=20=C5=A0iljak?= Date: Wed, 21 Dec 2022 11:44:16 +0100 Subject: [PATCH 2/4] events --- src/app.rs | 8 ++++++++ src/queue.rs | 2 ++ src/tabs/status.rs | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/app.rs b/src/app.rs index be0cc9172f..c5150e3fed 100644 --- a/src/app.rs +++ b/src/app.rs @@ -851,6 +851,14 @@ impl App { .push(branch, push_type, force, delete)?; flags.insert(NeedsUpdate::ALL); } + InternalEvent::Fetch(branch) => { + if let Err(error) = self.pull_popup.fetch(branch) { + self.queue.push(InternalEvent::ShowErrorMsg( + error.to_string(), + )); + } + flags.insert(NeedsUpdate::ALL); + } InternalEvent::Pull(branch) => { if let Err(error) = self.pull_popup.fetch(branch) { self.queue.push(InternalEvent::ShowErrorMsg( diff --git a/src/queue.rs b/src/queue.rs index dd033bedf0..a156216a36 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -105,6 +105,8 @@ pub enum InternalEvent { /// Push(String, PushType, bool, bool), /// + Fetch(String), + /// Pull(String), /// PushTags, diff --git a/src/tabs/status.rs b/src/tabs/status.rs index c27a062ffa..e9b8bf2cb9 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -594,6 +594,12 @@ impl Status { } } + fn fetch(&self) { + if let Some(branch) = self.git_branch_name.last() { + self.queue.push(InternalEvent::Fetch(branch)); + } + } + fn pull(&self) { if let Some(branch) = self.git_branch_name.last() { self.queue.push(InternalEvent::Pull(branch)); @@ -913,6 +919,12 @@ impl Component for Status { { self.push(false); Ok(EventState::Consumed) + } else if key_match(k, self.key_config.keys.fetch) + && !self.is_focus_on_diff() + && self.can_pull() + { + self.fetch(); + Ok(EventState::Consumed) } else if key_match(k, self.key_config.keys.pull) && !self.is_focus_on_diff() && self.can_pull() From 5a3cf97632810622b5ad72ad82b76c68ff2926f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alen=20=C5=A0iljak?= Date: Wed, 21 Dec 2022 11:49:02 +0100 Subject: [PATCH 3/4] using the fetch popup --- src/app.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index c5150e3fed..75214e981f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -852,7 +852,9 @@ impl App { flags.insert(NeedsUpdate::ALL); } InternalEvent::Fetch(branch) => { - if let Err(error) = self.pull_popup.fetch(branch) { + if let Err(error) = self.fetch_popup.fetch() + // .fetch(branch) + { self.queue.push(InternalEvent::ShowErrorMsg( error.to_string(), )); From 55c20ec7a757c19e3c033c989d7dae441bc789c9 Mon Sep 17 00:00:00 2001 From: extrawurst Date: Fri, 13 Jan 2023 14:27:49 +0100 Subject: [PATCH 4/4] cleanup and fix warnings --- src/app.rs | 10 ---------- src/queue.rs | 2 -- src/tabs/status.rs | 4 ++-- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/app.rs b/src/app.rs index 75214e981f..be0cc9172f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -851,16 +851,6 @@ impl App { .push(branch, push_type, force, delete)?; flags.insert(NeedsUpdate::ALL); } - InternalEvent::Fetch(branch) => { - if let Err(error) = self.fetch_popup.fetch() - // .fetch(branch) - { - self.queue.push(InternalEvent::ShowErrorMsg( - error.to_string(), - )); - } - flags.insert(NeedsUpdate::ALL); - } InternalEvent::Pull(branch) => { if let Err(error) = self.pull_popup.fetch(branch) { self.queue.push(InternalEvent::ShowErrorMsg( diff --git a/src/queue.rs b/src/queue.rs index a156216a36..dd033bedf0 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -105,8 +105,6 @@ pub enum InternalEvent { /// Push(String, PushType, bool, bool), /// - Fetch(String), - /// Pull(String), /// PushTags, diff --git a/src/tabs/status.rs b/src/tabs/status.rs index e9b8bf2cb9..89f36fc42a 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -595,8 +595,8 @@ impl Status { } fn fetch(&self) { - if let Some(branch) = self.git_branch_name.last() { - self.queue.push(InternalEvent::Fetch(branch)); + if self.can_pull() { + self.queue.push(InternalEvent::FetchRemotes); } }