Skip to content

Commit

Permalink
feat(git): test root commit with one tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rarescosma committed Oct 2, 2024
1 parent bba70d9 commit 6ec995c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/fixtures/test-latest-with-one-tag/commit.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .github/fixtures/test-latest-with-one-tag/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

### Feat

- Initial commit
- Add feature 1

<!-- generated by git-cliff -->
22 changes: 22 additions & 0 deletions git-cliff-core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,18 @@ mod test {
.to_string())
}

fn get_root_commit_hash() -> Result<String> {
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<String> {
Ok(str::from_utf8(
Command::new("git")
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 6ec995c

Please sign in to comment.