From 972f617603feb24d3348991fa12483b16e415911 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:03:15 -1000 Subject: Check a renamed file's diff leaves the rest out A new path is diffed across the whole commit so the rename can be found, and a filter then keeps that path alone. The rename commit touched one file, so a diff that dropped the filter passed. --- tests/t0107-diff.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/t0107-diff.sh b/tests/t0107-diff.sh index b779890..1f12220 100755 --- a/tests/t0107-diff.sh +++ b/tests/t0107-diff.sh @@ -136,7 +136,9 @@ test_expect_success 'stripping the highlight leaves every line intact' ' ' # The diffstat links a renamed file by its new name, and so does the log of -# that file, but the old name lies outside a diff limited to the new one. +# that file, but the old name lies outside a diff limited to the new one. That +# diff runs over the whole commit to find the rename, so the commit changes +# another file as well, which the limit still has to leave out. test_expect_success 'set up a renamed file' ' mkrepo repos/moved 1 && ( @@ -145,27 +147,32 @@ test_expect_success 'set up a renamed file' ' git add old.txt && git commit -m "add old.txt" && git mv old.txt new.txt && - git commit -m "rename old.txt" + echo changed >file-1 && + git commit -am "rename old.txt" ) && cgitrc_repo movedrc moved ' -test_expect_success 'the diff of a renamed file shows the rename' ' - cgit_rc movedrc "url=moved/diff/new.txt" >tmp && +test_expect_success 'the diff of a renamed file shows the rename alone' ' + cgit_ok movedrc "url=moved/diff/new.txt" >tmp && grep "diff --git a/old.txt b/new.txt" tmp && grep " (renamed from old.txt)" tmp && - ! grep "new file mode" tmp + grep "
1 file changed, 0 insertions, 0 deletions
" tmp && + ! grep "new file mode" tmp && + ! grep "a/file-1 b/file-1" tmp ' test_expect_success 'so does the commit page limited to the new name' ' - cgit_rc movedrc "url=moved/commit/new.txt" >tmp && + cgit_ok movedrc "url=moved/commit/new.txt" >tmp && grep "diff --git a/old.txt b/new.txt" tmp && - ! grep "new file mode" tmp + grep "
1 file changed, 0 insertions, 0 deletions
" tmp && + ! grep "new file mode" tmp && + ! grep "a/file-1 b/file-1" tmp ' test_expect_success 'a file added outright still shows as new' ' added=$(git -C repos/moved rev-parse HEAD~1) && - cgit_rc movedrc "url=moved/diff/old.txt&id=$added" >tmp && + cgit_ok movedrc "url=moved/diff/old.txt&id=$added" >tmp && grep "new file mode 100644" tmp && grep "
+10
" tmp ' -- cgit 2.12.1