Skip to content

[WIP] Status fetch #1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/keys/key_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/keys/key_list_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct KeysListFile {
pub open_file_tree: Option<GituiKeyEvent>,
pub file_find: Option<GituiKeyEvent>,
pub force_push: Option<GituiKeyEvent>,
pub fetch: Option<GituiKeyEvent>,
pub pull: Option<GituiKeyEvent>,
pub abort_merge: Option<GituiKeyEvent>,
pub undo_commit: Option<GituiKeyEvent>,
Expand Down Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
18 changes: 18 additions & 0 deletions src/tabs/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@ impl Status {
}
}

fn fetch(&self) {
if self.can_pull() {
self.queue.push(InternalEvent::FetchRemotes);
}
}

fn pull(&self) {
if let Some(branch) = self.git_branch_name.last() {
self.queue.push(InternalEvent::Pull(branch));
Expand Down Expand Up @@ -761,6 +767,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(),
Expand Down Expand Up @@ -907,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()
Expand Down