Skip to content

Commit

Permalink
fix(bump): correctly generate tag with prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Nov 30, 2021
1 parent d597208 commit 9e8d592
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/git/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub struct Tag {
impl TryFrom<Git2Tag<'_>> for Tag {
type Error = anyhow::Error;

fn try_from(tag: Git2Tag) -> std::prelude::rust_2015::Result<Self, Self::Error> {
fn try_from(tag: Git2Tag) -> std::result::Result<Self, Self::Error> {
let name = tag.name().expect("Unexpected unnamed tag");
Self::new(name, Some(tag.id()))
}
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ impl CocoGitto {
next_version.pre = Prerelease::new(pre_release)?;
}

let version_str = next_version.to_string();
let version_str = match &SETTINGS.tag_prefix {
None => next_version.to_string(),
Some(prefix) => format!("{}{}", prefix, next_version),
};

let origin = if current_version == Version::new(0, 0, 0) {
self.repository.get_first_commit()?.to_string()
Expand Down Expand Up @@ -484,6 +487,7 @@ impl CocoGitto {
&next_version,
hooks_config,
);

self.repository.add_all()?;

// Hook failed, we need to stop here and reset
Expand Down
24 changes: 24 additions & 0 deletions tests/cog_tests/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ fn auto_bump_major_from_latest_tag() -> Result<()> {
})
}

#[test]
fn auto_bump_with_prefix() -> Result<()> {
run_test_with_context(|context| {
let mut command = Command::cargo_bin("cog")?;

command.arg("bump").arg("--auto");
git_init()?;
std::fs::write(context.test_dir.join("cog.toml"), "tag_prefix = \"v\"")?;
git_commit("chore: init")?;
git_commit("feat(taef): feature")?;
git_commit("fix: bug fix")?;
git_tag("v1.0.0")?;
git_commit("feat(taef)!: feature")?;
git_commit("feat!: feature 1")?;
git_commit("feat: feature 2")?;

command.assert().success();

assert_that(&context.test_dir.join("CHANGELOG.md")).exists();
assert_tag("v2.0.0")?;
Ok(())
})
}

#[test]
fn auto_bump_patch_from_latest_tag() -> Result<()> {
run_test_with_context(|context| {
Expand Down

0 comments on commit 9e8d592

Please sign in to comment.