mirror of https://github.com/lapce/lapce.git
Fix/git commit silently fail missing username email (#2878)
* fix: Commit on freshly initialized repository. Fixes #2779 * fix: Prompt error message when Git user.name or user.email is missing. Fixes #1277. * Update CHANGELOG.md --------- Co-authored-by: Alexandre Leblanc <a.leblanc@kitai.dev>
This commit is contained in:
parent
e1f3892729
commit
83120215ad
|
@ -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
|
||||
|
|
|
@ -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::<Vec<_>>();
|
||||
|
||||
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<()> {
|
||||
|
|
Loading…
Reference in New Issue