cli: Fix `Message::get` bug

We were not propagating the error properly.
This commit is contained in:
Alexis Sellier 2023-04-26 12:52:20 +02:00
parent 44298df48f
commit 60fc50644f
No known key found for this signature in database
5 changed files with 7 additions and 11 deletions

View File

@ -93,7 +93,7 @@ fn comment(
repo: &storage::git::Repository,
signer: impl Signer,
) -> anyhow::Result<()> {
let message = options.message.clone().get("Enter a comment...");
let message = options.message.clone().get("Enter a comment...")?;
if message.is_empty() {
return Ok(());
}

View File

@ -34,7 +34,7 @@ pub fn handle_patch_message(
let commit_message = head_commit
.message()
.ok_or(anyhow!("commit summary is not valid UTF-8; aborting"))?;
let message = message.get(&format!("{commit_message}{PATCH_MSG}"));
let message = message.get(&format!("{commit_message}{PATCH_MSG}"))?;
let message = message.replace(PATCH_MSG.trim(), ""); // Delete help message.
let (title, description) = message.split_once("\n\n").unwrap_or((&message, ""));
let (title, description) = (title.trim(), description.trim());

View File

@ -100,7 +100,7 @@ pub fn run(
let head_oid = branch_oid(&head_branch)?;
let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
let message = message.get(REVISION_MSG);
let message = message.get(REVISION_MSG)?;
let message = message.replace(REVISION_MSG.trim(), "");
let message = message.trim();
let signer = term::signer(profile)?;

View File

@ -144,7 +144,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
.revisions()
.nth(revision_ix)
.ok_or_else(|| anyhow!("revision R{} does not exist", revision_ix))?;
let message = options.message.get(REVIEW_HELP_MSG);
let message = options.message.get(REVIEW_HELP_MSG)?;
let message = message.replace(REVIEW_HELP_MSG.trim(), "");
let message = if message.is_empty() {
None

View File

@ -16,20 +16,16 @@ pub enum Message {
impl Message {
/// Get the `Message` as a string according to the method.
pub fn get(self, help: &str) -> String {
pub fn get(self, help: &str) -> std::io::Result<String> {
let comment = match self {
Message::Edit => term::Editor::new()
.extension("markdown")
.edit(help)
.ok()
.flatten(),
Message::Edit => term::Editor::new().extension("markdown").edit(help)?,
Message::Blank => None,
Message::Text(c) => Some(c),
};
let comment = comment.unwrap_or_default();
let comment = comment.trim();
comment.to_owned()
Ok(comment.to_owned())
}
pub fn append(&mut self, arg: &str) {