From 394e01e81eaf8e5fafcccd77dfc03c1a0df77c0d Mon Sep 17 00:00:00 2001 From: Miguel Ramos Date: Mon, 11 Nov 2024 23:17:23 +0000 Subject: [PATCH] chore: tag repo feature --- crates/git/src/repo.rs | 11 +++++++++++ crates/git/tests/git_repo.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/crates/git/src/repo.rs b/crates/git/src/repo.rs index 0eab88f0..c14e36c8 100644 --- a/crates/git/src/repo.rs +++ b/crates/git/src/repo.rs @@ -393,4 +393,15 @@ impl Repository { Ok(branch) } + + pub fn tag(&self, tag: &str, message: Option) -> Result { + 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()), + )?) + } } diff --git a/crates/git/tests/git_repo.rs b/crates/git/tests/git_repo.rs index fd420bb9..2cd003b0 100644 --- a/crates/git/tests/git_repo.rs +++ b/crates/git/tests/git_repo.rs @@ -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/awesome@1.0.0", Some(String::from("feat: 1.0.0 version")))?; + let log = repo.log(None)?; + + assert!(tagged); + assert!(log.contains("tag: @scope/awesome@1.0.0")); + + remove_dir_all(&monorepo_root_dir)?; + + Ok(()) + } }