Skip to content

Commit

Permalink
fix crash on entering submodule #1510
Browse files Browse the repository at this point in the history
also do not allow opening submodule without workdir
  • Loading branch information
extrawurst committed Feb 17, 2023
1 parent 8f612c5 commit ba9b6d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `edit` command duplication ([#1489](https://github.com/extrawurst/gitui/issues/1489))
* syntax errors in `key_bindings.ron` will be logged ([#1491](https://github.com/extrawurst/gitui/issues/1491))
* commit hooks report "command not found" on Windows with wsl2 installed ([#1528](https://github.com/extrawurst/gitui/issues/1528))
* crashes on entering submodules ([#1510](https://github.com/extrawurst/gitui/issues/1510))

### Changed
* minimum supported rust version bumped to 1.64 (thank you `clap`)
Expand Down
18 changes: 13 additions & 5 deletions src/components/submodules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl DrawableComponent for SubmodulesListComponent {
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints(
[Constraint::Min(40), Constraint::Length(40)]
[Constraint::Min(40), Constraint::Length(60)]
.as_ref(),
)
.split(chunks_vertical[0]);
Expand Down Expand Up @@ -127,7 +127,7 @@ impl Component for SubmodulesListComponent {

out.push(CommandInfo::new(
strings::commands::open_submodule(&self.key_config),
self.is_valid_selection(),
self.can_open_submodule(),
true,
));

Expand Down Expand Up @@ -182,9 +182,11 @@ impl Component for SubmodulesListComponent {
.map(Into::into);
} else if key_match(e, self.key_config.keys.enter) {
if let Some(submodule) = self.selected_entry() {
self.queue.push(InternalEvent::OpenRepo {
path: submodule.path.clone(),
});
if submodule.status.is_in_wd() {
self.queue.push(InternalEvent::OpenRepo {
path: submodule.path.clone(),
});
}
}
} else if key_match(
e,
Expand Down Expand Up @@ -297,6 +299,12 @@ impl SubmodulesListComponent {
self.selected_entry().is_some()
}

fn can_open_submodule(&self) -> bool {
self.selected_entry()
.map(|s| s.status.is_in_wd())
.unwrap_or_default()
}

//TODO: dedup this almost identical with BranchListComponent
fn move_selection(&mut self, scroll: ScrollType) -> Result<bool> {
let new_selection = match scroll {
Expand Down
8 changes: 3 additions & 5 deletions src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use notify_debouncer_mini::{
new_debouncer, new_debouncer_opt, DebouncedEvent,
};
use scopetime::scope_time;
use std::{
path::Path, sync::mpsc::RecvError, thread, time::Duration,
};
use std::{path::Path, thread, time::Duration};

pub struct RepoWatcher {
receiver: crossbeam_channel::Receiver<()>,
Expand Down Expand Up @@ -54,7 +52,7 @@ impl RepoWatcher {
Result<Vec<DebouncedEvent>, Vec<Error>>,
>,
sender: &Sender<()>,
) -> Result<(), RecvError> {
) -> Result<()> {
loop {
let ev = receiver.recv()?;

Expand All @@ -66,7 +64,7 @@ impl RepoWatcher {
}

if !ev.is_empty() {
sender.send(()).expect("send error");
sender.send(())?;
}
}
}
Expand Down

0 comments on commit ba9b6d6

Please sign in to comment.