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