Jakub Narebski | d8faea9 | 2010-08-09 10:50:53 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='diff --relative tests' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | test_expect_success 'setup' ' |
| 7 | git commit --allow-empty -m empty && |
| 8 | echo content >file1 && |
| 9 | mkdir subdir && |
| 10 | echo other content >subdir/file2 && |
| 11 | git add . && |
| 12 | git commit -m one |
| 13 | ' |
| 14 | |
Junio C Hamano | f1e4fb2 | 2017-12-09 21:40:13 +0100 | [diff] [blame] | 15 | check_diff () { |
| 16 | dir=$1 |
| 17 | shift |
| 18 | expect=$1 |
| 19 | shift |
| 20 | cat >expected <<-EOF |
| 21 | diff --git a/$expect b/$expect |
| 22 | new file mode 100644 |
| 23 | index 0000000..25c05ef |
| 24 | --- /dev/null |
| 25 | +++ b/$expect |
| 26 | @@ -0,0 +1 @@ |
| 27 | +other content |
| 28 | EOF |
| 29 | test_expect_success "-p $*" " |
| 30 | git -C '$dir' diff -p $* HEAD^ >actual && |
| 31 | test_cmp expected actual |
| 32 | " |
Jakub Narebski | d8faea9 | 2010-08-09 10:50:53 -0400 | [diff] [blame] | 33 | } |
| 34 | |
Junio C Hamano | f1e4fb2 | 2017-12-09 21:40:13 +0100 | [diff] [blame] | 35 | check_numstat () { |
| 36 | dir=$1 |
| 37 | shift |
| 38 | expect=$1 |
| 39 | shift |
| 40 | cat >expected <<-EOF |
| 41 | 1 0 $expect |
| 42 | EOF |
| 43 | test_expect_success "--numstat $*" " |
| 44 | echo '1 0 $expect' >expected && |
| 45 | git -C '$dir' diff --numstat $* HEAD^ >actual && |
| 46 | test_cmp expected actual |
| 47 | " |
Jonathan Nieder | 6dd8883 | 2012-03-13 00:05:54 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Junio C Hamano | f1e4fb2 | 2017-12-09 21:40:13 +0100 | [diff] [blame] | 50 | check_stat () { |
| 51 | dir=$1 |
| 52 | shift |
| 53 | expect=$1 |
| 54 | shift |
| 55 | cat >expected <<-EOF |
| 56 | $expect | 1 + |
| 57 | 1 file changed, 1 insertion(+) |
| 58 | EOF |
| 59 | test_expect_success "--stat $*" " |
| 60 | git -C '$dir' diff --stat $* HEAD^ >actual && |
| 61 | test_i18ncmp expected actual |
| 62 | " |
Jakub Narebski | d8faea9 | 2010-08-09 10:50:53 -0400 | [diff] [blame] | 63 | } |
| 64 | |
Junio C Hamano | f1e4fb2 | 2017-12-09 21:40:13 +0100 | [diff] [blame] | 65 | check_raw () { |
| 66 | dir=$1 |
| 67 | shift |
| 68 | expect=$1 |
| 69 | shift |
| 70 | cat >expected <<-EOF |
| 71 | :000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A $expect |
| 72 | EOF |
| 73 | test_expect_success "--raw $*" " |
| 74 | git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual && |
| 75 | test_cmp expected actual |
| 76 | " |
Jakub Narebski | d8faea9 | 2010-08-09 10:50:53 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Jacob Keller | 6d7c17e | 2017-12-09 21:40:12 +0100 | [diff] [blame] | 79 | for type in diff numstat stat raw |
| 80 | do |
| 81 | check_$type . file2 --relative=subdir/ |
| 82 | check_$type . file2 --relative=subdir |
| 83 | check_$type subdir file2 --relative |
| 84 | check_$type . dir/file2 --relative=sub |
Jakub Narebski | d8faea9 | 2010-08-09 10:50:53 -0400 | [diff] [blame] | 85 | done |
| 86 | |
| 87 | test_done |