summaryrefslogtreecommitdiff
path: root/t/t6001-rev-list-merge-order.sh
blob: 35f167622472354b34b7cc4ed39a805a63e9ace6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/sh
#
# Copyright (c) 2005 Jon Seymour
#

test_description='Test rev-list --merge-order
'
. ./test-lib.sh

function do_commit
{
    git-commit-tree "$@" </dev/null
}

function check_adjacency
{
    read previous
    echo "= $previous"
    while read next
    do
        if ! (git-cat-file commit $previous | grep "^parent $next" >/dev/null)
        then
            echo "^ $next"
        else
            echo "| $next"
        fi
        previous=$next
    done
}

function sed_script
{
   for c in root a0 a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 l0 l1 l2 l3 l4 l5
   do
       echo -n "s/${!c}/$c/;"
   done
}

date >path0
git-update-cache --add path0
tree=$(git-write-tree)
root=$(do_commit $tree 2>/dev/null)
export GIT_COMMITTER_NAME=foobar  # to guarantee that the commit is different
l0=$(do_commit $tree -p $root)
l1=$(do_commit $tree -p $l0)
l2=$(do_commit $tree -p $l1)
a0=$(do_commit $tree -p $l2)
a1=$(do_commit $tree -p $a0)
export GIT_COMMITTER_NAME=foobar2 # to guarantee that the commit is different
b1=$(do_commit $tree -p $a0)
c1=$(do_commit $tree -p $b1)
export GIT_COMMITTER_NAME=foobar3 # to guarantee that the commit is different
b2=$(do_commit $tree -p $b1)
b3=$(do_commit $tree -p $b2)
c2=$(do_commit $tree -p $c1 -p $b2)
c3=$(do_commit $tree -p $c2)
a2=$(do_commit $tree -p $a1)
a3=$(do_commit $tree -p $a2)
b4=$(do_commit $tree -p $b3 -p $a3)
a4=$(do_commit $tree -p $a3 -p $b4 -p $c3)
l3=$(do_commit $tree -p $a4)
l4=$(do_commit $tree -p $l3)
l5=$(do_commit $tree -p $l4)
echo $l5 > .git/HEAD

git-rev-list --merge-order --show-breaks HEAD | sed "$(sed_script)" > actual-merge-order
cat > expected-merge-order <<EOF
= l5
| l4
| l3
= a4
| c3
| c2
| c1
^ b4
| b3
| b2
| b1
^ a3
| a2
| a1
= a0
| l2
| l1
| l0
= root
EOF

git-rev-list HEAD | check_adjacency | sed "$(sed_script)" > actual-default-order
normal_adjacency_count=$(git-rev-list HEAD | check_adjacency | grep -c "\^" | tr -d ' ')
merge_order_adjacency_count=$(git-rev-list --merge-order HEAD | check_adjacency | grep -c "\^" | tr -d ' ')

test_expect_success 'Testing that the rev-list has correct number of entries' '[ $(git-rev-list HEAD | wc -l) -eq 19 ]'
test_expect_success 'Testing that --merge-order produces the correct result' 'diff expected-merge-order actual-merge-order'
test_expect_success 'Testing that --merge-order produces as many or fewer discontinuities' '[ $merge_order_adjacency_count -le $normal_adjacency_count ]'

cat > expected-merge-order-1 <<EOF
c3
c2
c1
b3
b2
b1
a3
a2
a1
a0
l2
l1
l0
root
EOF

git-rev-list --merge-order $a3 $b3 $c3 | sed "$(sed_script)" > actual-merge-order-1
test_expect_success 'Testing multiple heads' 'diff expected-merge-order-1 actual-merge-order-1'

cat > expected-merge-order-2 <<EOF
c3
c2
c1
b3
b2
b1
a3
a2
EOF

git-rev-list --merge-order $a3 $b3 $c3 ^$a1 | sed "$(sed_script)" > actual-merge-order-2
test_expect_success 'Testing stop' 'diff expected-merge-order-2 actual-merge-order-2'

cat > expected-merge-order-3 <<EOF
c3
c2
c1
b3
b2
b1
a3
a2
a1
a0
l2
EOF

git-rev-list --merge-order $a3 $b3 $c3 ^$l1 | sed "$(sed_script)" > actual-merge-order-3
test_expect_success 'Testing stop in linear epoch' 'diff expected-merge-order-3 actual-merge-order-3'

cat > expected-merge-order-4 <<EOF
l5
l4
l3
a4
c3
c2
c1
b4
b3
b2
b1
a3
a2
a1
a0
l2
EOF

git-rev-list --merge-order $l5 ^$l1 | sed "$(sed_script)" > actual-merge-order-4
test_expect_success 'Testing start in linear epoch, stop after non-linear epoch' 'diff expected-merge-order-4 actual-merge-order-4'

git-rev-list --merge-order $l5 $l5 ^$l1 2>/dev/null | sed "$(sed_script)" > actual-merge-order-5
test_expect_success 'Testing duplicated start arguments' 'diff expected-merge-order-4 actual-merge-order-5'

test_expect_success 'Testing exclusion near merge' 'git-rev-list --merge-order $a4 ^$c3 2>/dev/null'

test_done