sparse-index: loose integration with cache_tree_verify()
[git] / t / t6019-rev-list-ancestry-path.sh
1 #!/bin/sh
2
3 test_description='--ancestry-path'
4
5 #          D---E-------F
6 #         /     \       \
7 #    B---C---G---H---I---J
8 #   /                     \
9 #  A-------K---------------L--M
10 #
11 #  D..M                 == E F G H I J K L M
12 #  --ancestry-path D..M == E F H I J L M
13 #
14 #  D..M -- M.t                 == M
15 #  --ancestry-path D..M -- M.t == M
16 #
17 #  F...I                 == F G H I
18 #  --ancestry-path F...I == F H I
19 #
20 #  G..M -- G.t                 == [nothing - was dropped in "-s ours" merge L]
21 #  --ancestry-path G..M -- G.t == L
22 #  --ancestry-path --simplify-merges G^..M -- G.t == G L
23
24 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
25 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
26
27 . ./test-lib.sh
28
29 test_merge () {
30         test_tick &&
31         git merge -s ours -m "$2" "$1" &&
32         git tag "$2"
33 }
34
35 test_expect_success setup '
36         test_commit A &&
37         test_commit B &&
38         test_commit C &&
39         test_commit D &&
40         test_commit E &&
41         test_commit F &&
42         git reset --hard C &&
43         test_commit G &&
44         test_merge E H &&
45         test_commit I &&
46         test_merge F J &&
47         git reset --hard A &&
48         test_commit K &&
49         test_merge J L &&
50         test_commit M
51 '
52
53 test_expect_success 'rev-list D..M' '
54         for c in E F G H I J K L M; do echo $c; done >expect &&
55         git rev-list --format=%s D..M |
56         sed -e "/^commit /d" |
57         sort >actual &&
58         test_cmp expect actual
59 '
60
61 test_expect_success 'rev-list --ancestry-path D..M' '
62         for c in E F H I J L M; do echo $c; done >expect &&
63         git rev-list --ancestry-path --format=%s D..M |
64         sed -e "/^commit /d" |
65         sort >actual &&
66         test_cmp expect actual
67 '
68
69 test_expect_success 'rev-list D..M -- M.t' '
70         echo M >expect &&
71         git rev-list --format=%s D..M -- M.t |
72         sed -e "/^commit /d" >actual &&
73         test_cmp expect actual
74 '
75
76 test_expect_success 'rev-list --ancestry-path D..M -- M.t' '
77         echo M >expect &&
78         git rev-list --ancestry-path --format=%s D..M -- M.t |
79         sed -e "/^commit /d" >actual &&
80         test_cmp expect actual
81 '
82
83 test_expect_success 'rev-list F...I' '
84         for c in F G H I; do echo $c; done >expect &&
85         git rev-list --format=%s F...I |
86         sed -e "/^commit /d" |
87         sort >actual &&
88         test_cmp expect actual
89 '
90
91 test_expect_success 'rev-list --ancestry-path F...I' '
92         for c in F H I; do echo $c; done >expect &&
93         git rev-list --ancestry-path --format=%s F...I |
94         sed -e "/^commit /d" |
95         sort >actual &&
96         test_cmp expect actual
97 '
98
99 # G.t is dropped in an "-s ours" merge
100 test_expect_success 'rev-list G..M -- G.t' '
101         git rev-list --format=%s G..M -- G.t |
102         sed -e "/^commit /d" >actual &&
103         test_must_be_empty actual
104 '
105
106 test_expect_success 'rev-list --ancestry-path G..M -- G.t' '
107         echo L >expect &&
108         git rev-list --ancestry-path --format=%s G..M -- G.t |
109         sed -e "/^commit /d" >actual &&
110         test_cmp expect actual
111 '
112
113 test_expect_success 'rev-list --ancestry-path --simplify-merges G^..M -- G.t' '
114         for c in G L; do echo $c; done >expect &&
115         git rev-list --ancestry-path --simplify-merges --format=%s G^..M -- G.t |
116         sed -e "/^commit /d" |
117         sort >actual &&
118         test_cmp expect actual
119 '
120
121 #   b---bc
122 #  / \ /
123 # a   X
124 #  \ / \
125 #   c---cb
126 #
127 # All refnames prefixed with 'x' to avoid confusion with the tags
128 # generated by test_commit on case-insensitive systems.
129 test_expect_success 'setup criss-cross' '
130         mkdir criss-cross &&
131         (cd criss-cross &&
132          git init &&
133          test_commit A &&
134          git checkout -b xb main &&
135          test_commit B &&
136          git checkout -b xc main &&
137          test_commit C &&
138          git checkout -b xbc xb -- &&
139          git merge xc &&
140          git checkout -b xcb xc -- &&
141          git merge xb &&
142          git checkout main)
143 '
144
145 # no commits in bc descend from cb
146 test_expect_success 'criss-cross: rev-list --ancestry-path cb..bc' '
147         (cd criss-cross &&
148          git rev-list --ancestry-path xcb..xbc > actual &&
149          test_must_be_empty actual)
150 '
151
152 # no commits in repository descend from cb
153 test_expect_success 'criss-cross: rev-list --ancestry-path --all ^cb' '
154         (cd criss-cross &&
155          git rev-list --ancestry-path --all ^xcb > actual &&
156          test_must_be_empty actual)
157 '
158
159 test_done