commit-graph: implement git-commit-graph write
[git/git.git] / t / t5318-commit-graph.sh
1 #!/bin/sh
2
3 test_description='commit graph'
4 . ./test-lib.sh
5
6 test_expect_success 'setup full repo' '
7 mkdir full &&
8 cd "$TRASH_DIRECTORY/full" &&
9 git init &&
10 objdir=".git/objects"
11 '
12
13 test_expect_success 'write graph with no packs' '
14 cd "$TRASH_DIRECTORY/full" &&
15 git commit-graph write --object-dir . &&
16 test_path_is_file info/commit-graph
17 '
18
19 test_expect_success 'create commits and repack' '
20 cd "$TRASH_DIRECTORY/full" &&
21 for i in $(test_seq 3)
22 do
23 test_commit $i &&
24 git branch commits/$i
25 done &&
26 git repack
27 '
28
29 test_expect_success 'write graph' '
30 cd "$TRASH_DIRECTORY/full" &&
31 graph1=$(git commit-graph write) &&
32 test_path_is_file $objdir/info/commit-graph
33 '
34
35 test_expect_success 'Add more commits' '
36 cd "$TRASH_DIRECTORY/full" &&
37 git reset --hard commits/1 &&
38 for i in $(test_seq 4 5)
39 do
40 test_commit $i &&
41 git branch commits/$i
42 done &&
43 git reset --hard commits/2 &&
44 for i in $(test_seq 6 7)
45 do
46 test_commit $i &&
47 git branch commits/$i
48 done &&
49 git reset --hard commits/2 &&
50 git merge commits/4 &&
51 git branch merge/1 &&
52 git reset --hard commits/4 &&
53 git merge commits/6 &&
54 git branch merge/2 &&
55 git reset --hard commits/3 &&
56 git merge commits/5 commits/7 &&
57 git branch merge/3 &&
58 git repack
59 '
60
61 # Current graph structure:
62 #
63 # __M3___
64 # / | \
65 # 3 M1 5 M2 7
66 # |/ \|/ \|
67 # 2 4 6
68 # |___/____/
69 # 1
70
71
72 test_expect_success 'write graph with merges' '
73 cd "$TRASH_DIRECTORY/full" &&
74 git commit-graph write &&
75 test_path_is_file $objdir/info/commit-graph
76 '
77
78 test_expect_success 'Add one more commit' '
79 cd "$TRASH_DIRECTORY/full" &&
80 test_commit 8 &&
81 git branch commits/8 &&
82 ls $objdir/pack | grep idx >existing-idx &&
83 git repack &&
84 ls $objdir/pack| grep idx | grep -v --file=existing-idx >new-idx
85 '
86
87 # Current graph structure:
88 #
89 # 8
90 # |
91 # __M3___
92 # / | \
93 # 3 M1 5 M2 7
94 # |/ \|/ \|
95 # 2 4 6
96 # |___/____/
97 # 1
98
99 test_expect_success 'write graph with new commit' '
100 cd "$TRASH_DIRECTORY/full" &&
101 git commit-graph write &&
102 test_path_is_file $objdir/info/commit-graph
103 '
104
105 test_expect_success 'write graph with nothing new' '
106 cd "$TRASH_DIRECTORY/full" &&
107 git commit-graph write &&
108 test_path_is_file $objdir/info/commit-graph
109 '
110
111 test_expect_success 'setup bare repo' '
112 cd "$TRASH_DIRECTORY" &&
113 git clone --bare --no-local full bare &&
114 cd bare &&
115 baredir="./objects"
116 '
117
118 test_expect_success 'write graph in bare repo' '
119 cd "$TRASH_DIRECTORY/bare" &&
120 git commit-graph write &&
121 test_path_is_file $baredir/info/commit-graph
122 '
123
124 test_done