Skip to content

Commit 83c1dfb

Browse files
cruesslerEliahKaganByron
authored
Add a test combining renames and edits on multiple branches (#2366)
* Add a test combining renames and edits on multiple branches * Regenerate `make_blame_rename_tracking_repo` archive Done by running gix clean -xde cargo nextest run --workspace --no-fail-fast on an Ubuntu 25.10 system, and verifying that all tests passed and that exactly one non-`.gitignore`'d archive was regenerated. * Unify diff style, with changes indicated by `number written out` instead of `number` This style is used in `gix-diff` already, and I think it's minimal and easy to understand. --------- Co-authored-by: Eliah Kagan <degeneracypressure@gmail.com> Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
1 parent 3774a03 commit 83c1dfb

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

gix-blame/tests/blame.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,21 @@ impl Fixture {
207207
suspect: head_id,
208208
})
209209
}
210+
211+
fn blame_file(
212+
&mut self,
213+
source_file_name: &bstr::BStr,
214+
options: gix_blame::Options,
215+
) -> Result<gix_blame::Outcome, gix_blame::Error> {
216+
gix_blame::file(
217+
&self.odb,
218+
self.suspect,
219+
None,
220+
&mut self.resource_cache,
221+
source_file_name,
222+
options,
223+
)
224+
}
210225
}
211226

212227
macro_rules! mktest {
@@ -584,6 +599,36 @@ mod rename_tracking {
584599

585600
Ok(())
586601
}
602+
603+
#[test]
604+
fn rename_and_change_in_merge_commit() -> gix_testtools::Result {
605+
let worktree_path = gix_testtools::scripted_fixture_read_only("make_blame_rename_tracking_repo.sh")?;
606+
607+
let mut fixture = Fixture::for_worktree_path(worktree_path.to_path_buf())?;
608+
let source_file_name = "change-and-renamed.txt";
609+
610+
let lines_blamed = fixture
611+
.blame_file(
612+
source_file_name.into(),
613+
gix_blame::Options {
614+
diff_algorithm: gix_diff::blob::Algorithm::Histogram,
615+
ranges: BlameRanges::default(),
616+
since: None,
617+
rewrites: Some(gix_diff::Rewrites::default()),
618+
debug_track_path: false,
619+
},
620+
)?
621+
.entries;
622+
623+
assert_eq!(lines_blamed.len(), 4);
624+
625+
let git_dir = worktree_path.join(".git");
626+
let baseline = Baseline::collect(git_dir.join("change-and-renamed.baseline"), source_file_name.into())?;
627+
628+
pretty_assertions::assert_eq!(lines_blamed, baseline);
629+
630+
Ok(())
631+
}
587632
}
588633

589634
fn fixture_path() -> gix_testtools::Result<PathBuf> {
Binary file not shown.

gix-blame/tests/fixtures/make_blame_rename_tracking_repo.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,33 @@ git checkout main
3535
git merge different-branch || true
3636

3737
git blame --porcelain after-rename.txt > .git/after-rename.baseline
38+
39+
echo -e "1\n2\n3\n4\n5\n" > change-and-rename.txt
40+
git add change-and-rename.txt
41+
git commit -q -m c2.1.1
42+
43+
echo -e "1\ntwo\n3\n4\n5\n" > change-and-rename.txt
44+
git add change-and-rename.txt
45+
git commit -q -m c2.1.2
46+
47+
git checkout -b branch-that-renames-file
48+
git reset --hard HEAD~1
49+
50+
echo -e "1\n2\n3\nfour\n5\n" > change-and-rename.txt
51+
git add change-and-rename.txt
52+
git commit -q -m c2.2.1
53+
54+
mv change-and-rename.txt change-and-renamed.txt
55+
git add change-and-rename.txt change-and-renamed.txt
56+
git commit -q -m c2.2.2
57+
58+
echo -e "1\n2\n3\nfour\nfive\n" > change-and-renamed.txt
59+
git add change-and-renamed.txt
60+
git commit -q -m c2.2.2
61+
62+
git checkout main
63+
git merge branch-that-renames-file || true
64+
git add change-and-rename.txt
65+
git commit --no-edit
66+
67+
git blame --porcelain change-and-renamed.txt > .git/change-and-renamed.baseline

0 commit comments

Comments
 (0)