Skip to content

Commit

Permalink
chore: tag repo feature
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelramos committed Nov 11, 2024
1 parent 3aea711 commit 394e01e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/git/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,15 @@ impl Repository {

Ok(branch)
}

pub fn tag(&self, tag: &str, message: Option<String>) -> Result<bool, RepositoryError> {
let msg = message.unwrap_or(tag.to_string());

Ok(execute(
"git",
self.location.as_path(),
["tag", "-a", tag, "-m", msg.as_str()],
|_, output| Ok(output.status.success()),
)?)
}
}
34 changes: 34 additions & 0 deletions crates/git/tests/git_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,38 @@ mod repo_tests {

Ok(())
}

#[test]
fn test_tag_repo() -> Result<(), RepositoryError> {
let monorepo_root_dir = create_monorepo()?;

let repo = Repository::new(monorepo_root_dir.as_path());
repo.create_branch("feature/awesome")?;

let main_file_path = monorepo_root_dir.join("main.mjs");
let mut main_file = File::create(main_file_path.as_path())?;
main_file.write_all(b"const msg = 'Hello';")?;

repo.add_all()?;

execute(
"git",
monorepo_root_dir.as_path(),
["commit", "-m", "chore: add main.mjs file"],
|_, stdout| Ok(stdout.status.success()),
)?;

repo.checkout("main")?;
repo.merge("feature/awesome")?;

let tagged = repo.tag("@scope/[email protected]", Some(String::from("feat: 1.0.0 version")))?;
let log = repo.log(None)?;

assert!(tagged);
assert!(log.contains("tag: @scope/[email protected]"));

remove_dir_all(&monorepo_root_dir)?;

Ok(())
}
}

0 comments on commit 394e01e

Please sign in to comment.