Jeff King | 74e8911 | 2017-05-19 08:54:56 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test direct comparison of blobs via git-diff' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | run_diff () { |
| 7 | # use full-index to make it easy to match the index line |
| 8 | git diff --full-index "$@" >diff |
| 9 | } |
| 10 | |
| 11 | check_index () { |
| 12 | grep "^index $1\\.\\.$2" diff |
| 13 | } |
| 14 | |
| 15 | check_mode () { |
| 16 | grep "^old mode $1" diff && |
| 17 | grep "^new mode $2" diff |
| 18 | } |
| 19 | |
| 20 | check_paths () { |
| 21 | grep "^diff --git a/$1 b/$2" diff |
| 22 | } |
| 23 | |
| 24 | test_expect_success 'create some blobs' ' |
| 25 | echo one >one && |
| 26 | echo two >two && |
| 27 | chmod +x two && |
| 28 | git add . && |
| 29 | |
| 30 | # cover systems where modes are ignored |
| 31 | git update-index --chmod=+x two && |
| 32 | |
| 33 | git commit -m base && |
| 34 | |
| 35 | sha1_one=$(git rev-parse HEAD:one) && |
| 36 | sha1_two=$(git rev-parse HEAD:two) |
| 37 | ' |
| 38 | |
| 39 | test_expect_success 'diff by sha1' ' |
| 40 | run_diff $sha1_one $sha1_two |
| 41 | ' |
| 42 | test_expect_success 'index of sha1 diff' ' |
| 43 | check_index $sha1_one $sha1_two |
| 44 | ' |
| 45 | test_expect_success 'sha1 diff uses arguments as paths' ' |
| 46 | check_paths $sha1_one $sha1_two |
| 47 | ' |
| 48 | test_expect_success 'sha1 diff has no mode change' ' |
| 49 | ! grep mode diff |
| 50 | ' |
| 51 | |
| 52 | test_expect_success 'diff by tree:path (run)' ' |
| 53 | run_diff HEAD:one HEAD:two |
| 54 | ' |
| 55 | test_expect_success 'index of tree:path diff' ' |
| 56 | check_index $sha1_one $sha1_two |
| 57 | ' |
Jeff King | 158b06c | 2017-05-19 08:59:15 -0400 | [diff] [blame] | 58 | test_expect_success 'tree:path diff uses filenames as paths' ' |
Jeff King | 74e8911 | 2017-05-19 08:54:56 -0400 | [diff] [blame] | 59 | check_paths one two |
| 60 | ' |
| 61 | test_expect_success 'tree:path diff shows mode change' ' |
| 62 | check_mode 100644 100755 |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'diff by ranged tree:path' ' |
| 66 | run_diff HEAD:one..HEAD:two |
| 67 | ' |
| 68 | test_expect_success 'index of ranged tree:path diff' ' |
| 69 | check_index $sha1_one $sha1_two |
| 70 | ' |
Jeff King | 158b06c | 2017-05-19 08:59:15 -0400 | [diff] [blame] | 71 | test_expect_success 'ranged tree:path diff uses filenames as paths' ' |
Jeff King | 74e8911 | 2017-05-19 08:54:56 -0400 | [diff] [blame] | 72 | check_paths one two |
| 73 | ' |
Jeff King | 101dd4d | 2017-05-19 08:55:11 -0400 | [diff] [blame] | 74 | test_expect_success 'ranged tree:path diff shows mode change' ' |
Jeff King | 74e8911 | 2017-05-19 08:54:56 -0400 | [diff] [blame] | 75 | check_mode 100644 100755 |
| 76 | ' |
| 77 | |
| 78 | test_expect_success 'diff blob against file' ' |
| 79 | run_diff HEAD:one two |
| 80 | ' |
| 81 | test_expect_success 'index of blob-file diff' ' |
| 82 | check_index $sha1_one $sha1_two |
| 83 | ' |
Jeff King | 30d005c | 2017-05-19 08:59:34 -0400 | [diff] [blame] | 84 | test_expect_success 'blob-file diff uses filename as paths' ' |
Jeff King | 74e8911 | 2017-05-19 08:54:56 -0400 | [diff] [blame] | 85 | check_paths one two |
| 86 | ' |
| 87 | test_expect_success FILEMODE 'blob-file diff shows mode change' ' |
| 88 | check_mode 100644 100755 |
| 89 | ' |
| 90 | |
Jeff King | 30d005c | 2017-05-19 08:59:34 -0400 | [diff] [blame] | 91 | test_expect_success 'blob-file diff prefers filename to sha1' ' |
| 92 | run_diff $sha1_one two && |
| 93 | check_paths two two |
| 94 | ' |
| 95 | |
Jeff King | 74e8911 | 2017-05-19 08:54:56 -0400 | [diff] [blame] | 96 | test_done |