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