Skip to content

gix-blame: add test for file with two roots #2066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions gix-blame/tests/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Binary file not shown.
40 changes: 40 additions & 0 deletions gix-blame/tests/fixtures/make_blame_two_roots_repo.sh
Original file line number Diff line number Diff line change
@@ -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
Loading