diff --git a/CHANGELOG.md b/CHANGELOG.md index d69edd12..3ae4da20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features/Changes - [#2723](https://github.com/lapce/lapce/pull/2723): Line wrapping based on width (no column-based yet) +- [#1277](https://github.com/lapce/lapce/pull/1277): Error message prompted on missing git user.email and/or user.name ### Bug Fixes - [#2779](https://github.com/lapce/lapce/pull/2779): Fix files detection on fresh git/VCS repository diff --git a/lapce-proxy/src/dispatch.rs b/lapce-proxy/src/dispatch.rs index 1ae5d4b3..92247ffc 100644 --- a/lapce-proxy/src/dispatch.rs +++ b/lapce-proxy/src/dispatch.rs @@ -13,6 +13,7 @@ use alacritty_terminal::{event::WindowSize, event_loop::Msg}; use anyhow::{anyhow, Context, Result}; use crossbeam_channel::Sender; +use git2::ErrorCode::NotFound; use git2::{build::CheckoutBuilder, DiffOptions, Oid, Repository}; use grep_matcher::Matcher; use grep_regex::RegexMatcherBuilder; @@ -31,7 +32,9 @@ RequestId, RpcError, }; use lapce_xi_rope::Rope; -use lsp_types::{Position, Range, TextDocumentItem, Url}; +use lsp_types::{ + MessageType, Position, Range, ShowMessageParams, TextDocumentItem, Url, +}; use parking_lot::Mutex; use crate::{ @@ -284,7 +287,15 @@ fn handle_notification(&mut self, rpc: ProxyNotification) { if let Some(workspace) = self.workspace.as_ref() { match git_commit(workspace, &message, diffs) { Ok(()) => (), - Err(e) => eprintln!("{e:?}"), + Err(e) => { + self.core_rpc.show_message( + "Git Commit failure".to_owned(), + ShowMessageParams { + typ: MessageType::ERROR, + message: e.to_string(), + }, + ); + } } } } @@ -1205,18 +1216,35 @@ fn git_commit( index.write()?; let tree = index.write_tree()?; let tree = repo.find_tree(tree)?; - let signature = repo.signature()?; - let parent = repo.head()?.peel_to_commit()?; - repo.commit( - Some("HEAD"), - &signature, - &signature, - message, - &tree, - &[&parent], - )?; - Ok(()) + match repo.signature() { + Ok(signature) => { + let parents = repo + .head() + .and_then(|head| Ok(vec![head.peel_to_commit()?])) + .unwrap_or(vec![]); + let parents_refs = parents.iter().collect::>(); + + repo.commit( + Some("HEAD"), + &signature, + &signature, + message, + &tree, + &parents_refs, + )?; + Ok(()) + } + Err(e) => match e.code() { + NotFound => Err(anyhow!( + "No user.name and/or user.email configured for this git repository." + )), + _ => Err(anyhow!( + "Error while creating commit's signature: {}", + e.message() + )), + }, + } } fn git_checkout(workspace_path: &Path, reference: &str) -> Result<()> {