Skip to content

Commit

Permalink
add error handling on potential error in ignore (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed Jul 10, 2020
1 parent fc142b4 commit cbd7511
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion asyncgit/src/sync/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static GITIGNORE: &str = ".gitignore";
/// add file or path to root ignore file
pub fn add_to_ignore(
repo_path: &str,
path_to_ignore: String,
path_to_ignore: &str,
) -> Result<()> {
scope_time!("add_to_ignore");

Expand Down
28 changes: 20 additions & 8 deletions src/components/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,27 @@ impl ChangesComponent {
false
}

fn add_to_ignore(&mut self) -> Result<bool> {
fn add_to_ignore(&mut self) -> bool {
if let Some(tree_item) = self.selection() {
sync::add_to_ignore(CWD, tree_item.info.full_path)?;
self.queue
.borrow_mut()
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
return Ok(true);
if let Err(e) =
sync::add_to_ignore(CWD, &tree_item.info.full_path)
{
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"ignore error:\n{}\nfile:\n{:?}",
e, tree_item.info.full_path
)),
);
} else {
self.queue.borrow_mut().push_back(
InternalEvent::Update(NeedsUpdate::ALL),
);

return true;
}
}
Ok(false)

false
}
}

Expand Down Expand Up @@ -306,7 +318,7 @@ impl Component for ChangesComponent {
if self.is_working_dir
&& !self.is_empty() =>
{
Ok(self.add_to_ignore()?)
Ok(self.add_to_ignore())
}
_ => Ok(false),
};
Expand Down

0 comments on commit cbd7511

Please sign in to comment.