cli: Fix `Message::get` bug
We were not propagating the error properly.
This commit is contained in:
parent
44298df48f
commit
60fc50644f
|
|
@ -93,7 +93,7 @@ fn comment(
|
||||||
repo: &storage::git::Repository,
|
repo: &storage::git::Repository,
|
||||||
signer: impl Signer,
|
signer: impl Signer,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let message = options.message.clone().get("Enter a comment...");
|
let message = options.message.clone().get("Enter a comment...")?;
|
||||||
if message.is_empty() {
|
if message.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ pub fn handle_patch_message(
|
||||||
let commit_message = head_commit
|
let commit_message = head_commit
|
||||||
.message()
|
.message()
|
||||||
.ok_or(anyhow!("commit summary is not valid UTF-8; aborting"))?;
|
.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 message = message.replace(PATCH_MSG.trim(), ""); // Delete help message.
|
||||||
let (title, description) = message.split_once("\n\n").unwrap_or((&message, ""));
|
let (title, description) = message.split_once("\n\n").unwrap_or((&message, ""));
|
||||||
let (title, description) = (title.trim(), description.trim());
|
let (title, description) = (title.trim(), description.trim());
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ pub fn run(
|
||||||
|
|
||||||
let head_oid = branch_oid(&head_branch)?;
|
let head_oid = branch_oid(&head_branch)?;
|
||||||
let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
|
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.replace(REVISION_MSG.trim(), "");
|
||||||
let message = message.trim();
|
let message = message.trim();
|
||||||
let signer = term::signer(profile)?;
|
let signer = term::signer(profile)?;
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
.revisions()
|
.revisions()
|
||||||
.nth(revision_ix)
|
.nth(revision_ix)
|
||||||
.ok_or_else(|| anyhow!("revision R{} does not exist", 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 = message.replace(REVIEW_HELP_MSG.trim(), "");
|
||||||
let message = if message.is_empty() {
|
let message = if message.is_empty() {
|
||||||
None
|
None
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,16 @@ pub enum Message {
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
/// Get the `Message` as a string according to the method.
|
/// 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 {
|
let comment = match self {
|
||||||
Message::Edit => term::Editor::new()
|
Message::Edit => term::Editor::new().extension("markdown").edit(help)?,
|
||||||
.extension("markdown")
|
|
||||||
.edit(help)
|
|
||||||
.ok()
|
|
||||||
.flatten(),
|
|
||||||
Message::Blank => None,
|
Message::Blank => None,
|
||||||
Message::Text(c) => Some(c),
|
Message::Text(c) => Some(c),
|
||||||
};
|
};
|
||||||
let comment = comment.unwrap_or_default();
|
let comment = comment.unwrap_or_default();
|
||||||
let comment = comment.trim();
|
let comment = comment.trim();
|
||||||
|
|
||||||
comment.to_owned()
|
Ok(comment.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(&mut self, arg: &str) {
|
pub fn append(&mut self, arg: &str) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue