-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add verbose option and rename option
- Loading branch information
Showing
4 changed files
with
114 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
use std::path::Path; | ||
|
||
use crate::cli::{LastVersionArgs, NextVersionArgs}; | ||
use crate::gitutils; | ||
use crate::gitutils::{self, CommandOptions}; | ||
use crate::versioning::Versioner; | ||
|
||
pub fn last_version(path: &Path, args: &LastVersionArgs) -> Option<String> { | ||
let repo = gitutils::get_repo(path); | ||
let mut remote = gitutils::get_remote(&repo, "origin"); | ||
gitutils::fetch_all(&mut remote).expect("Failed to fetch from remote"); | ||
let opts = CommandOptions { | ||
verbose: args.verbose, | ||
}; | ||
|
||
gitutils::fetch_all(&mut remote, Some(&opts)).expect("Failed to fetch from remote"); | ||
let pattern = args | ||
.pattern | ||
.clone() | ||
.unwrap_or("v{major}.{minor}.{patch}".to_string()); | ||
let versioner = get_versioner(&repo, pattern); | ||
if let Some(version) = versioner.last_version() { | ||
if args.checkout { | ||
gitutils::checkout_tag(&repo, &version.tag).expect("Failed to checkout tag"); | ||
gitutils::checkout_tag(&repo, &version.tag, Some(&opts)) | ||
.expect("Failed to checkout tag"); | ||
} | ||
println!("{}", version.tag); | ||
Some(version.tag) | ||
|
@@ -28,14 +33,17 @@ pub fn last_version(path: &Path, args: &LastVersionArgs) -> Option<String> { | |
pub fn next_version(path: &Path, args: &NextVersionArgs) -> Option<String> { | ||
let repo = gitutils::get_repo(path); | ||
let mut remote = gitutils::get_remote(&repo, "origin"); | ||
gitutils::fetch_all(&mut remote).expect("Failed to fetch from remote"); | ||
let opts = CommandOptions { | ||
verbose: args.verbose, | ||
}; | ||
gitutils::fetch_all(&mut remote, Some(&opts)).expect("Failed to fetch from remote"); | ||
let pattern = args | ||
.pattern | ||
.clone() | ||
.unwrap_or("v{major}.{minor}.{patch}".to_string()); | ||
let versioner = get_versioner(&repo, pattern); | ||
|
||
if let Some(version) = versioner.next_version(args.version_part.clone()) { | ||
if let Some(version) = versioner.next_version(args.increment.clone()) { | ||
if args.tag { | ||
let head = repo.head().unwrap(); | ||
let head_id = head.target().unwrap(); | ||
|
@@ -64,7 +72,7 @@ fn get_versioner(repo: &git2::Repository, pattern: String) -> Versioner { | |
mod tests { | ||
use super::*; | ||
use crate::cli::LastVersionArgs; | ||
use crate::versioning::VersionPart; | ||
use crate::versioning::Increment; | ||
use crate::{gitutils, testutils}; | ||
|
||
#[test] | ||
|
@@ -93,6 +101,7 @@ mod tests { | |
let args = LastVersionArgs { | ||
pattern: Some("flopha@{major}.{minor}.{patch}".to_string()), | ||
checkout: false, | ||
verbose: false, | ||
}; | ||
|
||
let result = last_version(td.path(), &args); | ||
|
@@ -116,6 +125,7 @@ mod tests { | |
let args = LastVersionArgs { | ||
pattern: Some("flopha@{major}.{minor}.{patch}".to_string()), | ||
checkout: false, | ||
verbose: false, | ||
}; | ||
let result = last_version(td.path(), &args); | ||
|
||
|
@@ -145,6 +155,7 @@ mod tests { | |
let args = LastVersionArgs { | ||
pattern: Some("flopha@{major}.{minor}.{patch}".to_string()), | ||
checkout: true, | ||
verbose: false, | ||
}; | ||
last_version(td.path(), &args); | ||
|
||
|
@@ -174,14 +185,15 @@ mod tests { | |
for tag in tags { | ||
create_new_remote_tag(&repo, &mut remote, tag, false); | ||
} | ||
gitutils::checkout_tag(&repo, "[email protected]").unwrap(); | ||
gitutils::checkout_tag(&repo, "[email protected]", None).unwrap(); | ||
gitutils::commit(&repo, "New commit").unwrap(); | ||
|
||
// When | ||
let args = NextVersionArgs { | ||
pattern: Some("flopha@{major}.{minor}.{patch}".to_string()), | ||
version_part: VersionPart::Patch, | ||
increment: Increment::Patch, | ||
tag: false, | ||
verbose: false, | ||
}; | ||
let result = next_version(td.path(), &args); | ||
|
||
|
@@ -205,14 +217,15 @@ mod tests { | |
for tag in tags { | ||
create_new_remote_tag(&repo, &mut remote, tag, false); | ||
} | ||
gitutils::checkout_tag(&repo, "[email protected]").unwrap(); | ||
gitutils::checkout_tag(&repo, "[email protected]", None).unwrap(); | ||
gitutils::commit(&repo, "New commit").unwrap(); | ||
|
||
// When | ||
let args = NextVersionArgs { | ||
pattern: Some("flopha@{major}.{minor}.{patch}".to_string()), | ||
version_part: VersionPart::Patch, | ||
increment: Increment::Patch, | ||
tag: true, | ||
verbose: false, | ||
}; | ||
next_version(td.path(), &args); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters