Skip to content

Commit

Permalink
fix(changelog): return error if there is not a latest tag to process
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Jul 19, 2021
1 parent 2f2b2fc commit 8232111
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions git-cliff-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub enum Error {
/// Error that may occur while grouping commits.
#[error("Grouping error: `{0}`")]
GroupError(String),
/// Error that may occur while generating changelog.
#[error("Changelog error: `{0}`")]
ChangelogError(String),
/// Error that may occur while template operations such as parse and render.
#[error("Template error: `{0}`")]
TemplateError(#[from] tera::Error),
Expand Down
6 changes: 5 additions & 1 deletion git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ pub fn run(mut args: Opt) -> Result<()> {
commit_range = Some(format!("{}..HEAD", last_tag));
}
} else if args.latest {
if let (Some(tag1), Some(tag2)) = (
if tags.len() < 2 {
return Err(Error::ChangelogError(String::from(
"latest tag cannot be processed",
)));
} else if let (Some(tag1), Some(tag2)) = (
tags.get_index(tags.len() - 2).map(|(k, _)| k),
tags.get_index(tags.len() - 1).map(|(k, _)| k),
) {
Expand Down

0 comments on commit 8232111

Please sign in to comment.