Skip to content

Commit 4e0da37

Browse files
authored
Support updating submodules (#1305)
1 parent 986d34a commit 4e0da37

File tree

5 files changed

+55
-10
lines changed

5 files changed

+55
-10
lines changed

asyncgit/src/sync/submodules.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//TODO:
2-
// #![allow(unused_variables, dead_code)]
3-
41
use std::path::{Path, PathBuf};
52

63
use git2::{
@@ -93,13 +90,16 @@ pub fn get_submodules(
9390
///
9491
pub fn update_submodule(
9592
repo_path: &RepoPath,
96-
path: &str,
93+
name: &str,
9794
) -> Result<()> {
95+
scope_time!("update_submodule");
96+
9897
let repo = repo(repo_path)?;
9998

100-
let mut submodule = repo.find_submodule(path)?;
99+
let mut submodule = repo.find_submodule(name)?;
101100

102101
let mut options = SubmoduleUpdateOptions::new();
102+
options.allow_fetch(true);
103103

104104
submodule.update(true, Some(&mut options))?;
105105

src/components/submodules.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ use super::{
55
};
66
use crate::{
77
keys::{key_match, SharedKeyConfig},
8-
queue::{InternalEvent, Queue},
9-
strings,
8+
queue::{InternalEvent, NeedsUpdate, Queue},
9+
strings, try_or_popup,
1010
ui::{self, Size},
1111
};
1212
use anyhow::Result;
1313
use asyncgit::sync::{
14-
get_submodules, repo_dir, submodule_parent_info, RepoPathRef,
15-
SubmoduleInfo, SubmoduleParentInfo,
14+
get_submodules, repo_dir, submodule_parent_info,
15+
update_submodule, RepoPathRef, SubmoduleInfo,
16+
SubmoduleParentInfo,
1617
};
1718
use crossterm::event::Event;
1819
use std::{cell::Cell, convert::TryInto};
@@ -129,6 +130,12 @@ impl Component for SubmodulesListComponent {
129130
true,
130131
));
131132

133+
out.push(CommandInfo::new(
134+
strings::commands::update_submodule(&self.key_config),
135+
self.is_valid_selection(),
136+
true,
137+
));
138+
132139
out.push(CommandInfo::new(
133140
strings::commands::open_submodule_parent(
134141
&self.key_config,
@@ -178,6 +185,26 @@ impl Component for SubmodulesListComponent {
178185
path: submodule.path.clone(),
179186
});
180187
}
188+
} else if key_match(
189+
e,
190+
self.key_config.keys.update_submodule,
191+
) {
192+
if let Some(submodule) = self.selected_entry() {
193+
try_or_popup!(
194+
self,
195+
"update submodule:",
196+
update_submodule(
197+
&self.repo.borrow(),
198+
&submodule.name,
199+
)
200+
);
201+
202+
self.update_submodules()?;
203+
204+
self.queue.push(InternalEvent::Update(
205+
NeedsUpdate::ALL,
206+
));
207+
}
181208
} else if key_match(
182209
e,
183210
self.key_config.keys.view_submodule_parent,

src/keys/key_list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub struct KeysList {
110110
pub tag_annotate: GituiKeyEvent,
111111
pub view_submodules: GituiKeyEvent,
112112
pub view_submodule_parent: GituiKeyEvent,
113+
pub update_submodule: GituiKeyEvent,
113114
}
114115

115116
#[rustfmt::skip]
@@ -190,6 +191,7 @@ impl Default for KeysList {
190191
tag_annotate: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL),
191192
view_submodules: GituiKeyEvent::new(KeyCode::Char('S'), KeyModifiers::SHIFT),
192193
view_submodule_parent: GituiKeyEvent::new(KeyCode::Char('p'), KeyModifiers::empty()),
194+
update_submodule: GituiKeyEvent::new(KeyCode::Char('u'), KeyModifiers::empty()),
193195
}
194196
}
195197
}

src/keys/key_list_file.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ pub struct KeysListFile {
8080
pub stage_unstage_item: Option<GituiKeyEvent>,
8181
pub tag_annotate: Option<GituiKeyEvent>,
8282
pub view_submodules: Option<GituiKeyEvent>,
83+
pub view_submodule_parent: Option<GituiKeyEvent>,
84+
pub update_dubmodule: Option<GituiKeyEvent>,
8385
}
8486

8587
impl KeysListFile {
@@ -168,7 +170,8 @@ impl KeysListFile {
168170
stage_unstage_item: self.stage_unstage_item.unwrap_or(default.stage_unstage_item),
169171
tag_annotate: self.tag_annotate.unwrap_or(default.tag_annotate),
170172
view_submodules: self.view_submodules.unwrap_or(default.view_submodules),
171-
view_submodule_parent: self.view_submodules.unwrap_or(default.view_submodule_parent),
173+
view_submodule_parent: self.view_submodule_parent.unwrap_or(default.view_submodule_parent),
174+
update_submodule: self.update_dubmodule.unwrap_or(default.update_submodule),
172175
}
173176
}
174177
}

src/strings.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,19 @@ pub mod commands {
743743
)
744744
}
745745

746+
pub fn update_submodule(
747+
key_config: &SharedKeyConfig,
748+
) -> CommandText {
749+
CommandText::new(
750+
format!(
751+
"Update [{}]",
752+
key_config.get_hint(key_config.keys.update_submodule),
753+
),
754+
"update submodule",
755+
CMD_GROUP_GENERAL,
756+
)
757+
}
758+
746759
pub fn continue_rebase(
747760
key_config: &SharedKeyConfig,
748761
) -> CommandText {

0 commit comments

Comments
 (0)