mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
Support updating submodules (#1305)
This commit is contained in:
parent
986d34a5ac
commit
4e0da37230
5 changed files with 55 additions and 10 deletions
|
|
@ -1,6 +1,3 @@
|
||||||
//TODO:
|
|
||||||
// #![allow(unused_variables, dead_code)]
|
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use git2::{
|
use git2::{
|
||||||
|
|
@ -93,13 +90,16 @@ pub fn get_submodules(
|
||||||
///
|
///
|
||||||
pub fn update_submodule(
|
pub fn update_submodule(
|
||||||
repo_path: &RepoPath,
|
repo_path: &RepoPath,
|
||||||
path: &str,
|
name: &str,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
scope_time!("update_submodule");
|
||||||
|
|
||||||
let repo = repo(repo_path)?;
|
let repo = repo(repo_path)?;
|
||||||
|
|
||||||
let mut submodule = repo.find_submodule(path)?;
|
let mut submodule = repo.find_submodule(name)?;
|
||||||
|
|
||||||
let mut options = SubmoduleUpdateOptions::new();
|
let mut options = SubmoduleUpdateOptions::new();
|
||||||
|
options.allow_fetch(true);
|
||||||
|
|
||||||
submodule.update(true, Some(&mut options))?;
|
submodule.update(true, Some(&mut options))?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,15 @@ use super::{
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
keys::{key_match, SharedKeyConfig},
|
keys::{key_match, SharedKeyConfig},
|
||||||
queue::{InternalEvent, Queue},
|
queue::{InternalEvent, NeedsUpdate, Queue},
|
||||||
strings,
|
strings, try_or_popup,
|
||||||
ui::{self, Size},
|
ui::{self, Size},
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use asyncgit::sync::{
|
use asyncgit::sync::{
|
||||||
get_submodules, repo_dir, submodule_parent_info, RepoPathRef,
|
get_submodules, repo_dir, submodule_parent_info,
|
||||||
SubmoduleInfo, SubmoduleParentInfo,
|
update_submodule, RepoPathRef, SubmoduleInfo,
|
||||||
|
SubmoduleParentInfo,
|
||||||
};
|
};
|
||||||
use crossterm::event::Event;
|
use crossterm::event::Event;
|
||||||
use std::{cell::Cell, convert::TryInto};
|
use std::{cell::Cell, convert::TryInto};
|
||||||
|
|
@ -129,6 +130,12 @@ impl Component for SubmodulesListComponent {
|
||||||
true,
|
true,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
out.push(CommandInfo::new(
|
||||||
|
strings::commands::update_submodule(&self.key_config),
|
||||||
|
self.is_valid_selection(),
|
||||||
|
true,
|
||||||
|
));
|
||||||
|
|
||||||
out.push(CommandInfo::new(
|
out.push(CommandInfo::new(
|
||||||
strings::commands::open_submodule_parent(
|
strings::commands::open_submodule_parent(
|
||||||
&self.key_config,
|
&self.key_config,
|
||||||
|
|
@ -178,6 +185,26 @@ impl Component for SubmodulesListComponent {
|
||||||
path: submodule.path.clone(),
|
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(
|
} else if key_match(
|
||||||
e,
|
e,
|
||||||
self.key_config.keys.view_submodule_parent,
|
self.key_config.keys.view_submodule_parent,
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ pub struct KeysList {
|
||||||
pub tag_annotate: GituiKeyEvent,
|
pub tag_annotate: GituiKeyEvent,
|
||||||
pub view_submodules: GituiKeyEvent,
|
pub view_submodules: GituiKeyEvent,
|
||||||
pub view_submodule_parent: GituiKeyEvent,
|
pub view_submodule_parent: GituiKeyEvent,
|
||||||
|
pub update_submodule: GituiKeyEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|
@ -190,6 +191,7 @@ impl Default for KeysList {
|
||||||
tag_annotate: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL),
|
tag_annotate: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL),
|
||||||
view_submodules: GituiKeyEvent::new(KeyCode::Char('S'), KeyModifiers::SHIFT),
|
view_submodules: GituiKeyEvent::new(KeyCode::Char('S'), KeyModifiers::SHIFT),
|
||||||
view_submodule_parent: GituiKeyEvent::new(KeyCode::Char('p'), KeyModifiers::empty()),
|
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 stage_unstage_item: Option<GituiKeyEvent>,
|
||||||
pub tag_annotate: Option<GituiKeyEvent>,
|
pub tag_annotate: Option<GituiKeyEvent>,
|
||||||
pub view_submodules: Option<GituiKeyEvent>,
|
pub view_submodules: Option<GituiKeyEvent>,
|
||||||
|
pub view_submodule_parent: Option<GituiKeyEvent>,
|
||||||
|
pub update_dubmodule: Option<GituiKeyEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeysListFile {
|
impl KeysListFile {
|
||||||
|
|
@ -168,7 +170,8 @@ impl KeysListFile {
|
||||||
stage_unstage_item: self.stage_unstage_item.unwrap_or(default.stage_unstage_item),
|
stage_unstage_item: self.stage_unstage_item.unwrap_or(default.stage_unstage_item),
|
||||||
tag_annotate: self.tag_annotate.unwrap_or(default.tag_annotate),
|
tag_annotate: self.tag_annotate.unwrap_or(default.tag_annotate),
|
||||||
view_submodules: self.view_submodules.unwrap_or(default.view_submodules),
|
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(
|
pub fn continue_rebase(
|
||||||
key_config: &SharedKeyConfig,
|
key_config: &SharedKeyConfig,
|
||||||
) -> CommandText {
|
) -> CommandText {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue