+
Skip to content

feat: recover message of last failed commit #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

gwennlbh
Copy link

@gwennlbh gwennlbh commented Jun 8, 2025

really useful when using precommit hooks :)

Comment on lines +9 to +11
use crate::recover::{
ask_for_recovery, clear_recovery_file, read_recovery_file, write_recovery_file,
};
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i might rename the file to recovery.rs and call recovery::ask etc instead of doing this

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

let CommitTitleDescription { title, description } =
ask_commit_title_description(&config, term).await?;
let commit = match read_recovery_file() {
Ok(Some(commit)) => match ask_for_recovery(term, commit.clone()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: Maybe we could improve the UX if we use the recovery value as default value for title & description.

It's nearly as fast for the user, and allow update value if necessary

Copy link
Author

@gwennlbh gwennlbh Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but since the function that asks for gitmoji inputs is called through another one that only returns title+description, we can't really get out just the emoji

Do we make different prompts (title + description) when recovering?

I do like the idea of limiting the number of key presses needed to just "retry" a commit, clicking enter like 4 times would be a bit much imo

)
.await?;

match status.success().then_some(()).ok_or(Error::FailToCommit) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔨 todo: should be simplify, why not having a simple if-then-else here ?


#[derive(Debug, derive_more::Error, derive_more::Display)]
#[display("Could not {action} recovery file: {source}")]
pub struct RecoveryError {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 suggestion: turn it into an enum with a single variant.

It's better if later we want to add more error like splitting read and write error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the action field has just a few constant string values, i think it could be turned into a enum with just source inside, what do you think? Also, will the annotations work with enums? I'm not familiar with that way of organizing errors (i... Usually just slap anyhow lol)

.join("lastmessage.json");

if !path.exists() {
let dir = path.parent().ok_or(RecoveryError {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔨 todo: create a private function that return the file to avoid duplication

fs::create_dir_all(dir).expect("Failed to create recovery directory");
}

let content = serde_json::to_string(&params).map_err(|source| RecoveryError {
Copy link
Owner

@ilaborie ilaborie Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔨 todo: write it in TOML (see config module that already read/write data in toml)

return Ok(None);
}

let content = fs::read_to_string(&path).map_err(|source| RecoveryError {
Copy link
Owner

@ilaborie ilaborie Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔨 todo: write it in TOML (see config module that already read/write data in toml)

Copy link
Owner

@ilaborie ilaborie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution.
This feature is a bit ➕

There are a few fixes to do before merge

@@ -33,6 +33,7 @@ indicatif = "0.17"
jiff = { version = "0.2.14", features = ["serde"] }
reqwest = { version = "0.12", features = ["json", "rustls-tls-native-roots"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.140"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: we could use TOML to store the data instead, the dependency is already present

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载