]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4063-diff-blobs.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t4063-diff-blobs.sh
CommitLineData
74e89110
JK
1#!/bin/sh
2
3test_description='test direct comparison of blobs via git-diff'
16d4bd4f
ÆAB
4
5TEST_PASSES_SANITIZE_LEAK=true
74e89110
JK
6. ./test-lib.sh
7
8run_diff () {
9 # use full-index to make it easy to match the index line
10 git diff --full-index "$@" >diff
11}
12
13check_index () {
14 grep "^index $1\\.\\.$2" diff
15}
16
17check_mode () {
18 grep "^old mode $1" diff &&
19 grep "^new mode $2" diff
20}
21
22check_paths () {
23 grep "^diff --git a/$1 b/$2" diff
24}
25
26test_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
41test_expect_success 'diff by sha1' '
42 run_diff $sha1_one $sha1_two
43'
44test_expect_success 'index of sha1 diff' '
45 check_index $sha1_one $sha1_two
46'
47test_expect_success 'sha1 diff uses arguments as paths' '
48 check_paths $sha1_one $sha1_two
49'
50test_expect_success 'sha1 diff has no mode change' '
51 ! grep mode diff
52'
53
54test_expect_success 'diff by tree:path (run)' '
55 run_diff HEAD:one HEAD:two
56'
57test_expect_success 'index of tree:path diff' '
58 check_index $sha1_one $sha1_two
59'
158b06ca 60test_expect_success 'tree:path diff uses filenames as paths' '
74e89110
JK
61 check_paths one two
62'
63test_expect_success 'tree:path diff shows mode change' '
64 check_mode 100644 100755
65'
66
67test_expect_success 'diff by ranged tree:path' '
68 run_diff HEAD:one..HEAD:two
69'
70test_expect_success 'index of ranged tree:path diff' '
71 check_index $sha1_one $sha1_two
72'
158b06ca 73test_expect_success 'ranged tree:path diff uses filenames as paths' '
74e89110
JK
74 check_paths one two
75'
101dd4de 76test_expect_success 'ranged tree:path diff shows mode change' '
74e89110
JK
77 check_mode 100644 100755
78'
79
80test_expect_success 'diff blob against file' '
81 run_diff HEAD:one two
82'
83test_expect_success 'index of blob-file diff' '
84 check_index $sha1_one $sha1_two
85'
30d005c0 86test_expect_success 'blob-file diff uses filename as paths' '
74e89110
JK
87 check_paths one two
88'
89test_expect_success FILEMODE 'blob-file diff shows mode change' '
90 check_mode 100644 100755
91'
92
30d005c0
JK
93test_expect_success 'blob-file diff prefers filename to sha1' '
94 run_diff $sha1_one two &&
95 check_paths two two
96'
97
74e89110 98test_done