#!/bin/sh setglobal test_description = ''diff --relative tests'' source ./test-lib.sh test_expect_success 'setup' ' git commit --allow-empty -m empty && echo content >file1 && mkdir subdir && echo other content >subdir/file2 && git add . && git commit -m one ' proc check_diff { setglobal expect = $1; shift cat >expected << """ diff --git a/$expect b/$expect new file mode 100644 index 0000000..25c05ef --- /dev/null +++ b/$expect @@ -0,0 +1 @@ +other content """ test_expect_success "-p $ifsjoin(Argv)" " git diff -p $ifsjoin(Argv) HEAD^ >actual && test_cmp expected actual " } proc check_numstat { setglobal expect = $1; shift cat >expected << """ 1 0 $expect """ test_expect_success "--numstat $ifsjoin(Argv)" " echo '1 0 $expect' >expected && git diff --numstat $ifsjoin(Argv) HEAD^ >actual && test_cmp expected actual " } proc check_stat { setglobal expect = $1; shift cat >expected << """ $expect | 1 + 1 file changed, 1 insertion(+) """ test_expect_success "--stat $ifsjoin(Argv)" " git diff --stat $ifsjoin(Argv) HEAD^ >actual && test_i18ncmp expected actual " } proc check_raw { setglobal expect = $1; shift cat >expected << """ :000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A $expect """ test_expect_success "--raw $ifsjoin(Argv)" " git diff --no-abbrev --raw $ifsjoin(Argv) HEAD^ >actual && test_cmp expected actual " } for type in [diff numstat stat raw] { check_$type file2 --relative=subdir/ check_$type file2 --relative=subdir check_$type dir/file2 --relative=sub } test_done