diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Fix hunk numbering and a leak in the ssdiff view
A hunk header that states no length was numbered from the wrong line, and the line a deferred row copied was never freed.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/t0106-diff.sh35
1 file changed, 35 insertions, 0 deletions
diff --git a/tests/t0106-diff.sh b/tests/t0106-diff.sh
index 82b645e..3e0d15c 100755
--- a/tests/t0106-diff.sh
+++ b/tests/t0106-diff.sh
@@ -16,4 +16,39 @@ test_expect_success 'find added line' '
grep "<div class=.add.>+5</div>" tmp
'
+# --- Side-by-side line numbers for a hunk that covers a single line ---------
+# git writes the length only when a hunk spans more than one line, so a header
+# reads "@@ -1 +1 @@". Requiring a comma after the number left those hunks
+# numbered from zero, which dropped the line-number link entirely.
+test_expect_success 'set up a repo with single-line hunks' '
+ mkrepo repos/hunk1 1 &&
+ (
+ cd repos/hunk1 &&
+ printf "only\n" >one.txt &&
+ git add one.txt &&
+ git commit -m "add one.txt" &&
+ printf "ONLY\n" >one.txt &&
+ git commit -am "change one.txt"
+ ) &&
+ {
+ echo "virtual-root=/" &&
+ echo "cache-size=0" &&
+ echo "repo.url=hunk1" &&
+ echo "repo.path=$PWD/repos/hunk1/.git"
+ } >hunk1rc &&
+ git -C repos/hunk1 diff HEAD~1 HEAD >raw.diff &&
+ grep "^@@ -1 +1 @@" raw.diff
+'
+
+test_expect_success 'ssdiff numbers a comma-less hunk from its real line' '
+ CGIT_CONFIG="$PWD/hunk1rc" QUERY_STRING="url=hunk1/diff/&dt=1" cgit >tmp &&
+ grep "#n1.>1</a>" tmp &&
+ ! grep "#n0.>0</a>" tmp
+'
+
+test_expect_success 'ssdiff still numbers a hunk that carries a length' '
+ cgit_query "url=foo/diff&dt=1" >tmp &&
+ grep "#n1.>1</a>" tmp
+'
+
test_done