diff --git a/gix-blame/tests/blame.rs b/gix-blame/tests/blame.rs index cdd91f852a9..d32d316ee53 100644 --- a/gix-blame/tests/blame.rs +++ b/gix-blame/tests/blame.rs @@ -333,6 +333,37 @@ fn diff_disparity() { } } +#[test] +fn file_that_was_added_in_two_branches() -> gix_testtools::Result { + let worktree_path = gix_testtools::scripted_fixture_read_only("make_blame_two_roots_repo.sh")?; + + let Fixture { + odb, + mut resource_cache, + suspect, + } = Fixture::for_worktree_path(worktree_path.to_path_buf())?; + + let source_file_name = "file-with-two-roots.txt"; + let lines_blamed = gix_blame::file( + &odb, + suspect, + None, + &mut resource_cache, + source_file_name.into(), + gix_blame::Options::default(), + )? + .entries; + + assert_eq!(lines_blamed.len(), 4); + + let git_dir = worktree_path.join(".git"); + let baseline = Baseline::collect(git_dir.join("file-with-two-roots.baseline"), source_file_name.into())?; + + pretty_assertions::assert_eq!(lines_blamed, baseline); + + Ok(()) +} + #[test] fn since() -> gix_testtools::Result { let Fixture { diff --git a/gix-blame/tests/fixtures/generated-archives/make_blame_two_roots_repo.tar b/gix-blame/tests/fixtures/generated-archives/make_blame_two_roots_repo.tar new file mode 100644 index 00000000000..bd43717b012 Binary files /dev/null and b/gix-blame/tests/fixtures/generated-archives/make_blame_two_roots_repo.tar differ diff --git a/gix-blame/tests/fixtures/make_blame_two_roots_repo.sh b/gix-blame/tests/fixtures/make_blame_two_roots_repo.sh new file mode 100755 index 00000000000..e59beb6c3da --- /dev/null +++ b/gix-blame/tests/fixtures/make_blame_two_roots_repo.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +git init -q +git config --local diff.algorithm histogram + +git config merge.ff false + +git checkout -q -b main + +seq 1 4 > unrelated-file.txt +git add unrelated-file.txt +git commit -q -m c1 + +seq 1 4 > file-with-two-roots.txt +git add file-with-two-roots.txt +git commit -q -m c2 + +seq 1 5 > file-with-two-roots.txt +git add file-with-two-roots.txt +git commit -q -m c3 + +git checkout -b different-branch +git reset --hard HEAD~2 + +seq 4 6 > file-with-two-roots.txt +git add file-with-two-roots.txt +git commit -q -m c10 + +seq 4 8 > file-with-two-roots.txt +git add file-with-two-roots.txt +git commit -q -m c11 + +git checkout main +git merge different-branch || true +seq 1 8 > file-with-two-roots.txt +git add file-with-two-roots.txt +git commit -q -m c20 + +git blame --porcelain file-with-two-roots.txt > .git/file-with-two-roots.baseline