#!/bin/sh # The rawdiff page serves a diff as plain text fit for patch. Every test # runs the git command the page mirrors and compares the two byte for byte, # over an ordinary commit, the parentless initial commit, a range, a path and # a rename. test_description='Check content on rawdiff page' . ./setup.sh test_expect_success 'a commit is served as text matching git diff' ' cgit_ok_url "foo/rawdiff" >tmp && sed "/^$/q" tmp | grep "^Content-Type: text/plain" && git -C repos/foo diff HEAD^.. >expect && strip_headers actual && test_cmp expect actual ' test_expect_success 'the initial commit matches git diff-tree' ' root=$(git -C repos/foo rev-list --max-parents=0 HEAD) && cgit_ok_url "foo/rawdiff&id=$root" >tmp && git -C repos/foo diff-tree -p --no-commit-id --root "$root" >expect && strip_headers actual && test_cmp expect actual ' test_expect_success 'a range matches git diff over the same range' ' id=$(git -C repos/foo rev-parse HEAD) && id2=$(git -C repos/foo rev-parse HEAD~3) && cgit_ok_url "foo/rawdiff&id=$id&id2=$id2" >tmp && git -C repos/foo diff HEAD~3..HEAD >expect && strip_headers actual && test_cmp expect actual ' # The grep keeps an empty expect, which an empty page would match, from # passing. test_expect_success 'a path limits the diff to that file' ' id=$(git -C repos/foo rev-parse HEAD) && id2=$(git -C repos/foo rev-parse HEAD~3) && cgit_ok_url "foo/rawdiff/file-4&id=$id&id2=$id2" >tmp && git -C repos/foo diff HEAD~3..HEAD -- file-4 >expect && strip_headers actual && test_cmp expect actual && grep "file-4" actual ' # The old name of a file renamed in the change joins the limit, so the diff # shows the rename, the same as git diff given both names. The rename adds a # line too, so git has to pair the files by similarity rather than as an # exact match, and the last grep makes sure the line is there. test_expect_success 'a renamed file is diffed as the rename' ' mkrepo_renamed repos/moved "echo eleven >>new.txt" && cgitrc_repo movedrc moved && cgit_ok movedrc "url=moved/rawdiff/new.txt" >tmp && git -C repos/moved diff HEAD^ HEAD -- old.txt new.txt >expect && strip_headers actual && test_cmp expect actual && grep "^rename from old.txt$" actual && grep "^+eleven$" actual ' test_done