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