-
Notifications
You must be signed in to change notification settings - Fork 13
fix(cli): edit option accepts argument #376
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ | |
|
|
||
| /// Read last commit from the specified file or fallbacks to ./.git/COMMIT_EDITMSG | ||
| #[arg(short = 'e', long)] | ||
| pub edit: bool, | ||
| pub edit: Option<String>, | ||
|
|
||
| /// Lower end of the commit range to lint | ||
| #[arg(short = 'f', long)] | ||
|
|
@@ -53,10 +53,12 @@ | |
| pub fn read(&self) -> Result<Vec<Message>, Error> { | ||
| // Check first whether or not the --edit option was supplied. When running from tooling such as | ||
| // `pre-commit`, stdin exists, so this needs to come first. | ||
| if self.edit { | ||
| let msg = std::fs::read_to_string("./.git/COMMIT_EDITMSG") | ||
| .expect("Failed to read './.git/COMMIT_EDITMSG'"); | ||
| return Ok(vec![Message::new(msg)]); | ||
| if let Some(edit) = self.edit.as_deref() { | ||
| if edit != "false" { | ||
| let msg = std::fs::read_to_string(edit) | ||
| .expect(format!("Failed to read commit message from {}", edit).as_str()); | ||
|
Check warning on line 59 in src/args.rs
|
||
| return Ok(vec![Message::new(msg)]); | ||
| } | ||
| } | ||
|
|
||
| // Otherwise, check for stdin and use the incoming text buffer from there if so. | ||
|
|
@@ -68,18 +70,30 @@ | |
| return Ok(vec![Message::new(buffer)]); | ||
| } | ||
|
|
||
| // And if none of the above, we're expecting to be reading directly from Git... | ||
| let config = ReadCommitMessageOptions { | ||
| from: self.from.clone(), | ||
| path: self.cwd.clone(), | ||
| to: self.to.clone(), | ||
| }; | ||
| if self.from.is_some() || self.to.is_some() { | ||
| // Reading directly from Git if from or to is specified. | ||
| let config = ReadCommitMessageOptions { | ||
| from: self.from.clone(), | ||
| path: self.cwd.clone(), | ||
| to: self.to.clone(), | ||
| }; | ||
|
|
||
| let messages = git::read(config) | ||
| .iter() | ||
| .map(|s| Message::new(s.to_string())) | ||
| .collect(); | ||
| let messages = git::read(config) | ||
| .iter() | ||
| .map(|s| Message::new(s.to_string())) | ||
| .collect(); | ||
|
|
||
| Ok(messages) | ||
| return Ok(messages); | ||
| } | ||
|
|
||
| let default_path = std::path::PathBuf::from(".git").join("COMMIT_EDITMSG"); | ||
| let msg = std::fs::read_to_string(&default_path).expect( | ||
|
Check warning on line 90 in src/args.rs
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| format!( | ||
| "Failed to read commit message from {}", | ||
| default_path.display() | ||
| ) | ||
| .as_str(), | ||
| ); | ||
| Ok(vec![Message::new(msg)]) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.