]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3303-notes-subtrees.sh
The third batch
[thirdparty/git.git] / t / t3303-notes-subtrees.sh
CommitLineData
0057c091
JH
1#!/bin/sh
2
3test_description='Test commit notes organized in subtrees'
4
d6c6b108 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
7a98d9ab 8TEST_PASSES_SANITIZE_LEAK=true
0057c091
JH
9. ./test-lib.sh
10
11number_of_commits=100
12
13start_note_commit () {
14 test_tick &&
15 cat <<INPUT_END
16commit refs/notes/commits
17committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
18data <<COMMIT
19notes
20COMMIT
21
22from refs/notes/commits^0
23deleteall
24INPUT_END
25
26}
27
28verify_notes () {
29 git log | grep "^ " > output &&
30 i=$number_of_commits &&
31 while [ $i -gt 0 ]; do
32 echo " commit #$i" &&
33 echo " note for commit #$i" &&
db5875aa 34 i=$(($i-1)) || return 1
0057c091
JH
35 done > expect &&
36 test_cmp expect output
37}
38
39test_expect_success "setup: create $number_of_commits commits" '
40
41 (
42 nr=0 &&
43 while [ $nr -lt $number_of_commits ]; do
44 nr=$(($nr+1)) &&
45 test_tick &&
db5875aa 46 cat <<INPUT_END || return 1
d6c6b108 47commit refs/heads/main
0057c091
JH
48committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
49data <<COMMIT
50commit #$nr
51COMMIT
52
53M 644 inline file
54data <<EOF
55file in commit #$nr
56EOF
57
58INPUT_END
59
60 done &&
61 test_tick &&
62 cat <<INPUT_END
63commit refs/notes/commits
64committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
65data <<COMMIT
66no notes
67COMMIT
68
69deleteall
70
71INPUT_END
72
73 ) |
74 git fast-import --quiet &&
75 git config core.notesRef refs/notes/commits
76'
77
78test_sha1_based () {
79 (
80 start_note_commit &&
81 nr=$number_of_commits &&
b6d775dd 82 git rev-list refs/heads/main >out &&
0057c091
JH
83 while read sha1; do
84 note_path=$(echo "$sha1" | sed "$1")
85 cat <<INPUT_END &&
86M 100644 inline $note_path
87data <<EOF
88note for commit #$nr
89EOF
90
91INPUT_END
92
93 nr=$(($nr-1))
b6d775dd
ÆAB
94 done <out
95 ) >gfi &&
96 git fast-import --quiet <gfi
0057c091
JH
97}
98
99test_expect_success 'test notes in 2/38-fanout' 'test_sha1_based "s|^..|&/|"'
100test_expect_success 'verify notes in 2/38-fanout' 'verify_notes'
101
0057c091
JH
102test_expect_success 'test notes in 2/2/36-fanout' 'test_sha1_based "s|^\(..\)\(..\)|\1/\2/|"'
103test_expect_success 'verify notes in 2/2/36-fanout' 'verify_notes'
104
851c2b37
JH
105test_expect_success 'test notes in 2/2/2/34-fanout' 'test_sha1_based "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
106test_expect_success 'verify notes in 2/2/2/34-fanout' 'verify_notes'
107
a099469b
JH
108test_same_notes () {
109 (
110 start_note_commit &&
111 nr=$number_of_commits &&
d6c6b108 112 git rev-list refs/heads/main |
a099469b
JH
113 while read sha1; do
114 first_note_path=$(echo "$sha1" | sed "$1")
115 second_note_path=$(echo "$sha1" | sed "$2")
116 cat <<INPUT_END &&
117M 100644 inline $second_note_path
118data <<EOF
119note for commit #$nr
120EOF
121
122M 100644 inline $first_note_path
123data <<EOF
124note for commit #$nr
125EOF
126
127INPUT_END
128
129 nr=$(($nr-1))
130 done
131 ) |
132 git fast-import --quiet
133}
134
851c2b37
JH
135test_expect_success 'test same notes in no fanout and 2/38-fanout' 'test_same_notes "s|^..|&/|" ""'
136test_expect_success 'verify same notes in no fanout and 2/38-fanout' 'verify_notes'
137
138test_expect_success 'test same notes in no fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
139test_expect_success 'verify same notes in no fanout and 2/2/36-fanout' 'verify_notes'
a099469b
JH
140
141test_expect_success 'test same notes in 2/38-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
142test_expect_success 'verify same notes in 2/38-fanout and 2/2/36-fanout' 'verify_notes'
143
851c2b37
JH
144test_expect_success 'test same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
145test_expect_success 'verify same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'verify_notes'
a099469b
JH
146
147test_concatenated_notes () {
148 (
149 start_note_commit &&
150 nr=$number_of_commits &&
d6c6b108 151 git rev-list refs/heads/main |
a099469b
JH
152 while read sha1; do
153 first_note_path=$(echo "$sha1" | sed "$1")
154 second_note_path=$(echo "$sha1" | sed "$2")
155 cat <<INPUT_END &&
156M 100644 inline $second_note_path
157data <<EOF
158second note for commit #$nr
159EOF
160
161M 100644 inline $first_note_path
162data <<EOF
163first note for commit #$nr
164EOF
165
166INPUT_END
167
168 nr=$(($nr-1))
169 done
170 ) |
171 git fast-import --quiet
172}
173
174verify_concatenated_notes () {
32a36b4d
JH
175 git log | grep "^ " > output &&
176 i=$number_of_commits &&
177 while [ $i -gt 0 ]; do
178 echo " commit #$i" &&
179 echo " first note for commit #$i" &&
d4990c4b 180 echo " " &&
32a36b4d 181 echo " second note for commit #$i" &&
db5875aa 182 i=$(($i-1)) || return 1
32a36b4d
JH
183 done > expect &&
184 test_cmp expect output
a099469b
JH
185}
186
851c2b37
JH
187test_expect_success 'test notes in no fanout concatenated with 2/38-fanout' 'test_concatenated_notes "s|^..|&/|" ""'
188test_expect_success 'verify notes in no fanout concatenated with 2/38-fanout' 'verify_concatenated_notes'
189
190test_expect_success 'test notes in no fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
191test_expect_success 'verify notes in no fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
a099469b
JH
192
193test_expect_success 'test notes in 2/38-fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
194test_expect_success 'verify notes in 2/38-fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
195
851c2b37
JH
196test_expect_success 'test notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|" "s|^\(..\)\(..\)|\1/\2/|"'
197test_expect_success 'verify notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'verify_concatenated_notes'
a099469b 198
0057c091 199test_done