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