mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-22 11:03:25 +03:00
Support updating submodules (#1305)
This commit is contained in:
parent
986d34a5ac
commit
4e0da37230
@ -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))?;
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ pub struct KeysListFile {
|
||||
pub stage_unstage_item: Option<GituiKeyEvent>,
|
||||
pub tag_annotate: Option<GituiKeyEvent>,
|
||||
pub view_submodules: Option<GituiKeyEvent>,
|
||||
pub view_submodule_parent: Option<GituiKeyEvent>,
|
||||
pub update_dubmodule: Option<GituiKeyEvent>,
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user