Skip to content

Commit

Permalink
fix: get latest tag based on semver format
Browse files Browse the repository at this point in the history
  • Loading branch information
pjvds authored and oknozor committed Jan 19, 2021
1 parent 9685924 commit 3c4f601
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/git/repository.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::status::Statuses;
use semver::Version;
use crate::error::ErrorKind;
use crate::error::ErrorKind::Git;
use crate::OidOf;
Expand Down Expand Up @@ -120,9 +121,19 @@ impl Repository {

pub(crate) fn get_latest_tag(&self) -> Result<String> {
let tag_names = self.0.tag_names(None)?;
let mut versions = Vec::new();

let tags = tag_names.iter().collect::<Vec<Option<&str>>>();
if let Some(Some(tag)) = tags.last() {
for tag in tag_names.iter().collect::<Vec<Option<&str>>>() {
if let Some(tag) = tag {
if let Ok(version) = Version::parse(tag) {
versions.push(version);
}
}
}

versions.sort();

if let Some(tag) = versions.last() {
Ok(tag.to_string())
} else {
Err(anyhow!("Unable to get any tag"))
Expand Down

0 comments on commit 3c4f601

Please sign in to comment.