commit-graph: when incompatible with graphs, indicate why
[git] / t / t6000-rev-list-misc.sh
1 #!/bin/sh
2
3 test_description='miscellaneous rev-list tests'
4
5 . ./test-lib.sh
6
7 test_expect_success setup '
8         echo content1 >wanted_file &&
9         echo content2 >unwanted_file &&
10         git add wanted_file unwanted_file &&
11         test_tick &&
12         git commit -m one
13 '
14
15 test_expect_success 'rev-list --objects heeds pathspecs' '
16         git rev-list --objects HEAD -- wanted_file >output &&
17         grep wanted_file output &&
18         ! grep unwanted_file output
19 '
20
21 test_expect_success 'rev-list --objects with pathspecs and deeper paths' '
22         mkdir foo &&
23         >foo/file &&
24         git add foo/file &&
25         test_tick &&
26         git commit -m two &&
27
28         git rev-list --objects HEAD -- foo >output &&
29         grep foo/file output &&
30
31         git rev-list --objects HEAD -- foo/file >output &&
32         grep foo/file output &&
33         ! grep unwanted_file output
34 '
35
36 test_expect_success 'rev-list --objects with pathspecs and copied files' '
37         git checkout --orphan junio-testcase &&
38         git rm -rf . &&
39
40         mkdir two &&
41         echo frotz >one &&
42         cp one two/three &&
43         git add one two/three &&
44         test_tick &&
45         git commit -m that &&
46
47         ONE=$(git rev-parse HEAD:one) &&
48         git rev-list --objects HEAD two >output &&
49         grep "$ONE two/three" output &&
50         ! grep one output
51 '
52
53 test_expect_success 'rev-list --objects --no-object-names has no space/names' '
54         git rev-list --objects --no-object-names HEAD >output &&
55         ! grep wanted_file output &&
56         ! grep unwanted_file output &&
57         ! grep " " output
58 '
59
60 test_expect_success 'rev-list --objects --no-object-names works with cat-file' '
61         git rev-list --objects --no-object-names --all >list-output &&
62         git cat-file --batch-check <list-output >cat-output &&
63         ! grep missing cat-output
64 '
65
66 test_expect_success '--no-object-names and --object-names are last-one-wins' '
67         git rev-list --objects --no-object-names --object-names --all >output &&
68         grep wanted_file output &&
69         git rev-list --objects --object-names --no-object-names --all >output &&
70         ! grep wanted_file output
71 '
72
73 test_expect_success 'rev-list A..B and rev-list ^A B are the same' '
74         test_tick &&
75         git commit --allow-empty -m another &&
76         git tag -a -m "annotated" v1.0 &&
77         git rev-list --objects ^v1.0^ v1.0 >expect &&
78         git rev-list --objects v1.0^..v1.0 >actual &&
79         test_cmp expect actual
80 '
81
82 test_expect_success 'propagate uninteresting flag down correctly' '
83         git rev-list --objects ^HEAD^{tree} HEAD^{tree} >actual &&
84         test_must_be_empty actual
85 '
86
87 test_expect_success 'symleft flag bit is propagated down from tag' '
88         git log --format="%m %s" --left-right v1.0...master >actual &&
89         cat >expect <<-\EOF &&
90         < another
91         < that
92         > two
93         > one
94         EOF
95         test_cmp expect actual
96 '
97
98 test_expect_success 'rev-list can show index objects' '
99         # Of the blobs and trees in the index, note:
100         #
101         #   - we do not show two/three, because it is the
102         #     same blob as "one", and we show objects only once
103         #
104         #   - we do show the tree "two", because it has a valid cache tree
105         #     from the last commit
106         #
107         #   - we do not show the root tree; since we updated the index, it
108         #     does not have a valid cache tree
109         #
110         echo only-in-index >only-in-index &&
111         test_when_finished "git reset --hard" &&
112         rev1=$(git rev-parse HEAD:one) &&
113         rev2=$(git rev-parse HEAD:two) &&
114         revi=$(git hash-object only-in-index) &&
115         cat >expect <<-EOF &&
116         $rev1 one
117         $revi only-in-index
118         $rev2 two
119         EOF
120         git add only-in-index &&
121         git rev-list --objects --indexed-objects >actual &&
122         test_cmp expect actual
123 '
124
125 test_expect_success 'rev-list can negate index objects' '
126         git rev-parse HEAD >expect &&
127         git rev-list -1 --objects HEAD --not --indexed-objects >actual &&
128         test_cmp expect actual
129 '
130
131 test_expect_success '--bisect and --first-parent can be combined' '
132         git rev-list --bisect --first-parent HEAD
133 '
134
135 test_expect_success '--header shows a NUL after each commit' '
136         # We know that there is no Q in the true payload; names and
137         # addresses of the authors and the committers do not have
138         # any, and object names or header names do not, either.
139         git rev-list --header --max-count=2 HEAD |
140         nul_to_q |
141         grep "^Q" >actual &&
142         cat >expect <<-EOF &&
143         Q$(git rev-parse HEAD~1)
144         Q
145         EOF
146         test_cmp expect actual
147 '
148
149 test_expect_success 'rev-list --end-of-options' '
150         git update-ref refs/heads/--output=yikes HEAD &&
151         git rev-list --end-of-options --output=yikes >actual &&
152         test_path_is_missing yikes &&
153         git rev-list HEAD >expect &&
154         test_cmp expect actual
155 '
156
157 test_expect_success 'rev-list --count' '
158         count=$(git rev-list --count HEAD) &&
159         git rev-list HEAD >actual &&
160         test_line_count = $count actual
161 '
162
163 test_expect_success 'rev-list --count --objects' '
164         count=$(git rev-list --count --objects HEAD) &&
165         git rev-list --objects HEAD >actual &&
166         test_line_count = $count actual
167 '
168
169 test_done