keep commit msg on hook-fail (#1036)

fixes #1035
This commit is contained in:
Stephan Dilly 2021-12-09 21:12:31 +01:00 committed by GitHub
parent cd639b29c0
commit 6249491484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 25 deletions

View File

@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Fixed
- Keep commit message when pre-commit hook fails ([#1035](https://github.com/extrawurst/gitui/issues/1035))
## [0.19] - 2021-12-08 - Bare Repo Support
**finder highlighting matches**

View File

@ -42,7 +42,7 @@
- Fast and intuitive **keyboard only** control
- Context based help (**no need to memorize** tons of hot-keys)
- Inspect, commit, and amend changes (incl. hooks: _commit-msg_/_post-commit_)
- Inspect, commit, and amend changes (incl. hooks: _pre-commit_,_commit-msg_,_post-commit_)
- Stage, unstage, revert and reset files, hunks and lines
- Stashing (save, pop, apply, drop, and inspect)
- Push/Fetch to/from remote

View File

@ -60,7 +60,7 @@ pub(crate) fn signature_allow_undefined_name(
signature
}
/// this does not run any git hooks
/// this does not run any git hooks, git-hooks have to be executed manually, checkout `hooks_commit_msg` for example
pub fn commit(repo_path: &RepoPath, msg: &str) -> Result<CommitId> {
scope_time!("commit");

View File

@ -30,6 +30,11 @@ use tui::{
Frame,
};
enum CommitResult {
ComitDone,
Aborted,
}
enum Mode {
Normal,
Amend(CommitId),
@ -175,11 +180,23 @@ impl CommitComponent {
}
let msg = self.input.get_text().to_string();
if matches!(
self.commit_with_msg(msg)?,
CommitResult::ComitDone
) {
self.hide();
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
self.input.clear();
self.commit_with_msg(msg)
}
fn commit_with_msg(&mut self, msg: String) -> Result<()> {
Ok(())
}
fn commit_with_msg(
&mut self,
msg: String,
) -> Result<CommitResult> {
if let HookResult::NotOk(e) =
sync::hooks_pre_commit(&self.repo.borrow())?
{
@ -188,7 +205,7 @@ impl CommitComponent {
"pre-commit hook error:\n{}",
e
)));
return Ok(());
return Ok(CommitResult::Aborted);
}
let mut msg = message_prettify(msg, Some(b'#'))?;
if let HookResult::NotOk(e) =
@ -199,28 +216,19 @@ impl CommitComponent {
"commit-msg hook error:\n{}",
e
)));
return Ok(());
return Ok(CommitResult::Aborted);
}
let res = match &self.mode {
Mode::Normal => sync::commit(&self.repo.borrow(), &msg),
match &self.mode {
Mode::Normal => sync::commit(&self.repo.borrow(), &msg)?,
Mode::Amend(amend) => {
sync::amend(&self.repo.borrow(), *amend, &msg)
sync::amend(&self.repo.borrow(), *amend, &msg)?
}
Mode::Merge(ids) => {
sync::merge_commit(&self.repo.borrow(), &msg, ids)
sync::merge_commit(&self.repo.borrow(), &msg, ids)?
}
};
if let Err(e) = res {
log::error!("commit error: {}", &e);
self.queue.push(InternalEvent::ShowErrorMsg(format!(
"commit failed:\n{}",
&e
)));
return Ok(());
}
if let HookResult::NotOk(e) =
sync::hooks_post_commit(&self.repo.borrow())?
{
@ -231,11 +239,7 @@ impl CommitComponent {
)));
}
self.hide();
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
Ok(())
Ok(CommitResult::ComitDone)
}
fn can_commit(&self) -> bool {