From 4e0da372309af3f17e05b57baaaf240c1ae3ca07 Mon Sep 17 00:00:00 2001 From: extrawurst <776816+extrawurst@users.noreply.github.com> Date: Wed, 31 Aug 2022 11:40:52 +0200 Subject: [PATCH] Support updating submodules (#1305) --- asyncgit/src/sync/submodules.rs | 10 +++++----- src/components/submodules.rs | 35 +++++++++++++++++++++++++++++---- src/keys/key_list.rs | 2 ++ src/keys/key_list_file.rs | 5 ++++- src/strings.rs | 13 ++++++++++++ 5 files changed, 55 insertions(+), 10 deletions(-) diff --git a/asyncgit/src/sync/submodules.rs b/asyncgit/src/sync/submodules.rs index b32a67d8..b69dde36 100644 --- a/asyncgit/src/sync/submodules.rs +++ b/asyncgit/src/sync/submodules.rs @@ -1,6 +1,3 @@ -//TODO: -// #![allow(unused_variables, dead_code)] - use std::path::{Path, PathBuf}; use git2::{ @@ -93,13 +90,16 @@ pub fn get_submodules( /// pub fn update_submodule( repo_path: &RepoPath, - path: &str, + name: &str, ) -> Result<()> { + scope_time!("update_submodule"); + let repo = repo(repo_path)?; - let mut submodule = repo.find_submodule(path)?; + let mut submodule = repo.find_submodule(name)?; let mut options = SubmoduleUpdateOptions::new(); + options.allow_fetch(true); submodule.update(true, Some(&mut options))?; diff --git a/src/components/submodules.rs b/src/components/submodules.rs index 58eb0e44..0ae0fbc6 100644 --- a/src/components/submodules.rs +++ b/src/components/submodules.rs @@ -5,14 +5,15 @@ use super::{ }; use crate::{ keys::{key_match, SharedKeyConfig}, - queue::{InternalEvent, Queue}, - strings, + queue::{InternalEvent, NeedsUpdate, Queue}, + strings, try_or_popup, ui::{self, Size}, }; use anyhow::Result; use asyncgit::sync::{ - get_submodules, repo_dir, submodule_parent_info, RepoPathRef, - SubmoduleInfo, SubmoduleParentInfo, + get_submodules, repo_dir, submodule_parent_info, + update_submodule, RepoPathRef, SubmoduleInfo, + SubmoduleParentInfo, }; use crossterm::event::Event; use std::{cell::Cell, convert::TryInto}; @@ -129,6 +130,12 @@ impl Component for SubmodulesListComponent { true, )); + out.push(CommandInfo::new( + strings::commands::update_submodule(&self.key_config), + self.is_valid_selection(), + true, + )); + out.push(CommandInfo::new( strings::commands::open_submodule_parent( &self.key_config, @@ -178,6 +185,26 @@ impl Component for SubmodulesListComponent { path: submodule.path.clone(), }); } + } else if key_match( + e, + self.key_config.keys.update_submodule, + ) { + if let Some(submodule) = self.selected_entry() { + try_or_popup!( + self, + "update submodule:", + update_submodule( + &self.repo.borrow(), + &submodule.name, + ) + ); + + self.update_submodules()?; + + self.queue.push(InternalEvent::Update( + NeedsUpdate::ALL, + )); + } } else if key_match( e, self.key_config.keys.view_submodule_parent, diff --git a/src/keys/key_list.rs b/src/keys/key_list.rs index c28a0ced..b54ad80d 100644 --- a/src/keys/key_list.rs +++ b/src/keys/key_list.rs @@ -110,6 +110,7 @@ pub struct KeysList { pub tag_annotate: GituiKeyEvent, pub view_submodules: GituiKeyEvent, pub view_submodule_parent: GituiKeyEvent, + pub update_submodule: GituiKeyEvent, } #[rustfmt::skip] @@ -190,6 +191,7 @@ impl Default for KeysList { tag_annotate: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL), view_submodules: GituiKeyEvent::new(KeyCode::Char('S'), KeyModifiers::SHIFT), view_submodule_parent: GituiKeyEvent::new(KeyCode::Char('p'), KeyModifiers::empty()), + update_submodule: GituiKeyEvent::new(KeyCode::Char('u'), KeyModifiers::empty()), } } } diff --git a/src/keys/key_list_file.rs b/src/keys/key_list_file.rs index 189c43d1..4d1a1618 100644 --- a/src/keys/key_list_file.rs +++ b/src/keys/key_list_file.rs @@ -80,6 +80,8 @@ pub struct KeysListFile { pub stage_unstage_item: Option, pub tag_annotate: Option, pub view_submodules: Option, + pub view_submodule_parent: Option, + pub update_dubmodule: Option, } impl KeysListFile { @@ -168,7 +170,8 @@ impl KeysListFile { stage_unstage_item: self.stage_unstage_item.unwrap_or(default.stage_unstage_item), tag_annotate: self.tag_annotate.unwrap_or(default.tag_annotate), view_submodules: self.view_submodules.unwrap_or(default.view_submodules), - view_submodule_parent: self.view_submodules.unwrap_or(default.view_submodule_parent), + view_submodule_parent: self.view_submodule_parent.unwrap_or(default.view_submodule_parent), + update_submodule: self.update_dubmodule.unwrap_or(default.update_submodule), } } } diff --git a/src/strings.rs b/src/strings.rs index d781a995..61470799 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -743,6 +743,19 @@ pub mod commands { ) } + pub fn update_submodule( + key_config: &SharedKeyConfig, + ) -> CommandText { + CommandText::new( + format!( + "Update [{}]", + key_config.get_hint(key_config.keys.update_submodule), + ), + "update submodule", + CMD_GROUP_GENERAL, + ) + } + pub fn continue_rebase( key_config: &SharedKeyConfig, ) -> CommandText {