From 6ec995c39e135448998a2a455335b15baed96d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rare=C8=99=20Cosma?= Date: Wed, 2 Oct 2024 17:03:33 +0300 Subject: [PATCH] feat(git): test root commit with one tag --- .../test-latest-with-one-tag/commit.sh | 2 +- .../test-latest-with-one-tag/expected.md | 1 + git-cliff-core/src/repo.rs | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/fixtures/test-latest-with-one-tag/commit.sh b/.github/fixtures/test-latest-with-one-tag/commit.sh index 6c5c90caaf..361943d085 100755 --- a/.github/fixtures/test-latest-with-one-tag/commit.sh +++ b/.github/fixtures/test-latest-with-one-tag/commit.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "Initial commit" +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: initial commit" GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "feat: add feature 1" git tag v0.1.0 diff --git a/.github/fixtures/test-latest-with-one-tag/expected.md b/.github/fixtures/test-latest-with-one-tag/expected.md index 1b15d95c46..e7fdd52b94 100644 --- a/.github/fixtures/test-latest-with-one-tag/expected.md +++ b/.github/fixtures/test-latest-with-one-tag/expected.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### Feat +- Initial commit - Add feature 1 diff --git a/git-cliff-core/src/repo.rs b/git-cliff-core/src/repo.rs index 35bd1403bd..a666a504b6 100644 --- a/git-cliff-core/src/repo.rs +++ b/git-cliff-core/src/repo.rs @@ -472,6 +472,18 @@ mod test { .to_string()) } + fn get_root_commit_hash() -> Result { + Ok(str::from_utf8( + Command::new("git") + .args(["rev-list", "--max-parents=0", "HEAD"]) + .output()? + .stdout + .as_ref(), + )? + .trim_ascii_end() + .to_string()) + } + fn get_last_tag() -> Result { Ok(str::from_utf8( Command::new("git") @@ -594,6 +606,16 @@ mod test { Ok(()) } + #[test] + fn includes_root_commit() -> Result<()> { + let repository = get_repository()?; + let commits = repository.commits(None, true, None, None)?; + let root_commit = + AppCommit::from(&commits.last().expect("no commits found").clone()); + assert_eq!(get_root_commit_hash()?, root_commit.id); + Ok(()) + } + fn create_temp_repo() -> (Repository, TempDir) { let temp_dir = TempDir::with_prefix("git-cliff-").expect("failed to create temp dir");