commit: integrate commit graph with commit parsing
[git/git.git] / t / t5318-commit-graph.sh
CommitLineData
f237c8b6
DS
1#!/bin/sh
2
3test_description='commit graph'
4. ./test-lib.sh
5
6test_expect_success 'setup full repo' '
7 mkdir full &&
8 cd "$TRASH_DIRECTORY/full" &&
9 git init &&
177722b3 10 git config core.commitGraph true &&
f237c8b6
DS
11 objdir=".git/objects"
12'
13
14test_expect_success 'write graph with no packs' '
15 cd "$TRASH_DIRECTORY/full" &&
16 git commit-graph write --object-dir . &&
17 test_path_is_file info/commit-graph
18'
19
20test_expect_success 'create commits and repack' '
21 cd "$TRASH_DIRECTORY/full" &&
22 for i in $(test_seq 3)
23 do
24 test_commit $i &&
25 git branch commits/$i
26 done &&
27 git repack
28'
29
177722b3
DS
30graph_git_two_modes() {
31 git -c core.graph=true $1 >output
32 git -c core.graph=false $1 >expect
33 test_cmp output expect
34}
35
36graph_git_behavior() {
37 MSG=$1
38 DIR=$2
39 BRANCH=$3
40 COMPARE=$4
41 test_expect_success "check normal git operations: $MSG" '
42 cd "$TRASH_DIRECTORY/$DIR" &&
43 graph_git_two_modes "log --oneline $BRANCH" &&
44 graph_git_two_modes "log --topo-order $BRANCH" &&
45 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
46 graph_git_two_modes "branch -vv" &&
47 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
48 '
49}
50
51graph_git_behavior 'no graph' full commits/3 commits/1
52
2a2e32bd
DS
53graph_read_expect() {
54 OPTIONAL=""
55 NUM_CHUNKS=3
56 if test ! -z $2
57 then
58 OPTIONAL=" $2"
59 NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
60 fi
61 cat >expect <<- EOF
62 header: 43475048 1 1 $NUM_CHUNKS 0
63 num_commits: $1
64 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
65 EOF
66 git commit-graph read >output &&
67 test_cmp expect output
68}
69
f237c8b6
DS
70test_expect_success 'write graph' '
71 cd "$TRASH_DIRECTORY/full" &&
72 graph1=$(git commit-graph write) &&
2a2e32bd
DS
73 test_path_is_file $objdir/info/commit-graph &&
74 graph_read_expect "3"
f237c8b6
DS
75'
76
177722b3
DS
77graph_git_behavior 'graph exists' full commits/3 commits/1
78
f237c8b6
DS
79test_expect_success 'Add more commits' '
80 cd "$TRASH_DIRECTORY/full" &&
81 git reset --hard commits/1 &&
82 for i in $(test_seq 4 5)
83 do
84 test_commit $i &&
85 git branch commits/$i
86 done &&
87 git reset --hard commits/2 &&
88 for i in $(test_seq 6 7)
89 do
90 test_commit $i &&
91 git branch commits/$i
92 done &&
93 git reset --hard commits/2 &&
94 git merge commits/4 &&
95 git branch merge/1 &&
96 git reset --hard commits/4 &&
97 git merge commits/6 &&
98 git branch merge/2 &&
99 git reset --hard commits/3 &&
100 git merge commits/5 commits/7 &&
101 git branch merge/3 &&
102 git repack
103'
104
105# Current graph structure:
106#
107# __M3___
108# / | \
109# 3 M1 5 M2 7
110# |/ \|/ \|
111# 2 4 6
112# |___/____/
113# 1
114
f237c8b6
DS
115test_expect_success 'write graph with merges' '
116 cd "$TRASH_DIRECTORY/full" &&
117 git commit-graph write &&
2a2e32bd
DS
118 test_path_is_file $objdir/info/commit-graph &&
119 graph_read_expect "10" "large_edges"
f237c8b6
DS
120'
121
177722b3
DS
122graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
123graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3
124graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3
125
f237c8b6
DS
126test_expect_success 'Add one more commit' '
127 cd "$TRASH_DIRECTORY/full" &&
128 test_commit 8 &&
129 git branch commits/8 &&
130 ls $objdir/pack | grep idx >existing-idx &&
131 git repack &&
132 ls $objdir/pack| grep idx | grep -v --file=existing-idx >new-idx
133'
134
135# Current graph structure:
136#
137# 8
138# |
139# __M3___
140# / | \
141# 3 M1 5 M2 7
142# |/ \|/ \|
143# 2 4 6
144# |___/____/
145# 1
146
177722b3
DS
147graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1
148graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2
149
f237c8b6
DS
150test_expect_success 'write graph with new commit' '
151 cd "$TRASH_DIRECTORY/full" &&
152 git commit-graph write &&
2a2e32bd
DS
153 test_path_is_file $objdir/info/commit-graph &&
154 graph_read_expect "11" "large_edges"
f237c8b6
DS
155'
156
177722b3
DS
157graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
158graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2
159
f237c8b6
DS
160test_expect_success 'write graph with nothing new' '
161 cd "$TRASH_DIRECTORY/full" &&
162 git commit-graph write &&
2a2e32bd
DS
163 test_path_is_file $objdir/info/commit-graph &&
164 graph_read_expect "11" "large_edges"
f237c8b6
DS
165'
166
177722b3
DS
167graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
168graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2
169
f237c8b6
DS
170test_expect_success 'setup bare repo' '
171 cd "$TRASH_DIRECTORY" &&
172 git clone --bare --no-local full bare &&
173 cd bare &&
177722b3 174 git config core.commitGraph true &&
f237c8b6
DS
175 baredir="./objects"
176'
177
177722b3
DS
178graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1
179graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2
180
f237c8b6
DS
181test_expect_success 'write graph in bare repo' '
182 cd "$TRASH_DIRECTORY/bare" &&
183 git commit-graph write &&
2a2e32bd
DS
184 test_path_is_file $baredir/info/commit-graph &&
185 graph_read_expect "11" "large_edges"
f237c8b6
DS
186'
187
177722b3
DS
188graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
189graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
190
f237c8b6 191test_done