Merge branch 'fixes/2.45.1/2.41' into fixes/2.45.1/2.42
[alt-git.git] / t / t3303-notes-subtrees.sh
blobbc9b791d1b9ed2a780de4544232f769e093072b1
1 #!/bin/sh
3 test_description='Test commit notes organized in subtrees'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 number_of_commits=100
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
22 from refs/notes/commits^0
23 deleteall
24 INPUT_END
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
39 test_expect_success "setup: create $number_of_commits commits" '
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
53 M 644 inline file
54 data <<EOF
55 file in commit #$nr
56 EOF
58 INPUT_END
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
69 deleteall
71 INPUT_END
73 ) |
74 git fast-import --quiet &&
75 git config core.notesRef refs/notes/commits
78 test_sha1_based () {
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
91 INPUT_END
93 nr=$(($nr-1))
94 done <out
95 ) >gfi &&
96 git fast-import --quiet <gfi
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'
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'
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'
108 test_same_notes () {
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
122 M 100644 inline $first_note_path
123 data <<EOF
124 note for commit #$nr
127 INPUT_END
129 nr=$(($nr-1))
130 done
132 git fast-import --quiet
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'
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'
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'
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'
147 test_concatenated_notes () {
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
161 M 100644 inline $first_note_path
162 data <<EOF
163 first note for commit #$nr
166 INPUT_END
168 nr=$(($nr-1))
169 done
171 git fast-import --quiet
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
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'
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'
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'
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'
199 test_done