blob: 3e0d15c2140e71c1e00e09b3efd2bb9d81e98503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh

test_description='Check content on diff page'
. ./setup.sh

test_expect_success 'generate foo/diff' 'cgit_url "foo/diff" >tmp'
test_expect_success 'find diff header' 'grep "a/file-5 b/file-5" tmp'
test_expect_success 'find blob link' 'grep "<a href=./foo/tree/file-5?id=" tmp'
test_expect_success 'find added file' 'grep "new file mode 100644" tmp'

test_expect_success 'find hunk header' '
	grep "<div class=.hunk.>@@ -0,0 +1 @@</div>" tmp
'

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