Skip to content

Commit e97a3af

Browse files
fix(cli): refactor based on coderabbitai
Signed-off-by: KeisukeYamashita <[email protected]>
1 parent 261f923 commit e97a3af

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/args.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ impl Args {
5353
pub fn read(&self) -> Result<Vec<Message>, Error> {
5454
// Check first whether or not the --edit option was supplied. When running from tooling such as
5555
// `pre-commit`, stdin exists, so this needs to come first.
56-
if let Some(edit) = self.edit.clone() {
56+
if let Some(edit) = self.edit.as_deref() {
5757
if edit != "false" {
58-
let msg = std::fs::read_to_string(edit.clone())
58+
let msg = std::fs::read_to_string(edit)
5959
.expect(format!("Failed to read commit message from {}", edit).as_str());
6060
return Ok(vec![Message::new(msg)]);
6161
}
@@ -70,7 +70,7 @@ impl Args {
7070
return Ok(vec![Message::new(buffer)]);
7171
}
7272

73-
if self.from.is_some() || self.from.is_some() {
73+
if self.from.is_some() || self.to.is_some() {
7474
// Reading directly from Git if from or to is specified.
7575
let config = ReadCommitMessageOptions {
7676
from: self.from.clone(),
@@ -86,8 +86,14 @@ impl Args {
8686
return Ok(messages);
8787
}
8888

89-
let msg = std::fs::read_to_string("./.git/COMMIT_EDITMSG")
90-
.expect("Failed to read commit message from ./.git/COMMIT_EDITMSG");
89+
let default_path = std::path::PathBuf::from(".git").join("COMMIT_EDITMSG");
90+
let msg = std::fs::read_to_string(&default_path).expect(
91+
format!(
92+
"Failed to read commit message from {}",
93+
default_path.display()
94+
)
95+
.as_str(),
96+
);
9197
Ok(vec![Message::new(msg)])
9298
}
9399
}

0 commit comments

Comments
 (0)