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