t3200: unset core.logallrefupdates when testing reflog creation
[alt-git.git] / t / t5318-commit-graph.sh
bloba380419b65bdf1ecace4c23831e76bc8a7d81962
1 #!/bin/sh
3 test_description='commit graph'
4 . ./test-lib.sh
6 test_expect_success 'setup full repo' '
7 mkdir full &&
8 cd "$TRASH_DIRECTORY/full" &&
9 git init &&
10 git config core.commitGraph true &&
11 objdir=".git/objects"
14 test_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
20 test_expect_success 'create commits and repack' '
21 cd "$TRASH_DIRECTORY/full" &&
22 for i in $(test_seq 3)
24 test_commit $i &&
25 git branch commits/$i
26 done &&
27 git repack
30 graph_git_two_modes() {
31 git -c core.graph=true $1 >output
32 git -c core.graph=false $1 >expect
33 test_cmp output expect
36 graph_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"
51 graph_git_behavior 'no graph' full commits/3 commits/1
53 graph_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)))
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
70 test_expect_success 'write graph' '
71 cd "$TRASH_DIRECTORY/full" &&
72 graph1=$(git commit-graph write) &&
73 test_path_is_file $objdir/info/commit-graph &&
74 graph_read_expect "3"
77 graph_git_behavior 'graph exists' full commits/3 commits/1
79 test_expect_success 'Add more commits' '
80 cd "$TRASH_DIRECTORY/full" &&
81 git reset --hard commits/1 &&
82 for i in $(test_seq 4 5)
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)
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
105 # Current graph structure:
107 # __M3___
108 # / | \
109 # 3 M1 5 M2 7
110 # |/ \|/ \|
111 # 2 4 6
112 # |___/____/
115 test_expect_success 'write graph with merges' '
116 cd "$TRASH_DIRECTORY/full" &&
117 git commit-graph write &&
118 test_path_is_file $objdir/info/commit-graph &&
119 graph_read_expect "10" "large_edges"
122 graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
123 graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3
124 graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3
126 test_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
135 # Current graph structure:
139 # __M3___
140 # / | \
141 # 3 M1 5 M2 7
142 # |/ \|/ \|
143 # 2 4 6
144 # |___/____/
147 graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1
148 graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2
150 test_expect_success 'write graph with new commit' '
151 cd "$TRASH_DIRECTORY/full" &&
152 git commit-graph write &&
153 test_path_is_file $objdir/info/commit-graph &&
154 graph_read_expect "11" "large_edges"
157 graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
158 graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2
160 test_expect_success 'write graph with nothing new' '
161 cd "$TRASH_DIRECTORY/full" &&
162 git commit-graph write &&
163 test_path_is_file $objdir/info/commit-graph &&
164 graph_read_expect "11" "large_edges"
167 graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
168 graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2
170 test_expect_success 'build graph from latest pack with closure' '
171 cd "$TRASH_DIRECTORY/full" &&
172 cat new-idx | git commit-graph write --stdin-packs &&
173 test_path_is_file $objdir/info/commit-graph &&
174 graph_read_expect "9" "large_edges"
177 graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1
178 graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2
180 test_expect_success 'build graph from commits with closure' '
181 cd "$TRASH_DIRECTORY/full" &&
182 git tag -a -m "merge" tag/merge merge/2 &&
183 git rev-parse tag/merge >commits-in &&
184 git rev-parse merge/1 >>commits-in &&
185 cat commits-in | git commit-graph write --stdin-commits &&
186 test_path_is_file $objdir/info/commit-graph &&
187 graph_read_expect "6"
190 graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1
191 graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2
193 test_expect_success 'build graph from commits with append' '
194 cd "$TRASH_DIRECTORY/full" &&
195 git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
196 test_path_is_file $objdir/info/commit-graph &&
197 graph_read_expect "10" "large_edges"
200 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
201 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
203 test_expect_success 'setup bare repo' '
204 cd "$TRASH_DIRECTORY" &&
205 git clone --bare --no-local full bare &&
206 cd bare &&
207 git config core.commitGraph true &&
208 baredir="./objects"
211 graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1
212 graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2
214 test_expect_success 'write graph in bare repo' '
215 cd "$TRASH_DIRECTORY/bare" &&
216 git commit-graph write &&
217 test_path_is_file $baredir/info/commit-graph &&
218 graph_read_expect "11" "large_edges"
221 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
222 graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
224 test_done