archive: handle commits with an empty tree
[git/jnareb-git.git] / t / t3303-notes-subtrees.sh
blob704aee81ef5618048bba5209629a0dfde136fdb3
1 #!/bin/sh
3 test_description='Test commit notes organized in subtrees'
5 . ./test-lib.sh
7 number_of_commits=100
9 start_note_commit () {
10 test_tick &&
11 cat <<INPUT_END
12 commit refs/notes/commits
13 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
14 data <<COMMIT
15 notes
16 COMMIT
18 from refs/notes/commits^0
19 deleteall
20 INPUT_END
24 verify_notes () {
25 git log | grep "^ " > output &&
26 i=$number_of_commits &&
27 while [ $i -gt 0 ]; do
28 echo " commit #$i" &&
29 echo " note for commit #$i" &&
30 i=$(($i-1));
31 done > expect &&
32 test_cmp expect output
35 test_expect_success "setup: create $number_of_commits commits" '
38 nr=0 &&
39 while [ $nr -lt $number_of_commits ]; do
40 nr=$(($nr+1)) &&
41 test_tick &&
42 cat <<INPUT_END
43 commit refs/heads/master
44 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
45 data <<COMMIT
46 commit #$nr
47 COMMIT
49 M 644 inline file
50 data <<EOF
51 file in commit #$nr
52 EOF
54 INPUT_END
56 done &&
57 test_tick &&
58 cat <<INPUT_END
59 commit refs/notes/commits
60 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
61 data <<COMMIT
62 no notes
63 COMMIT
65 deleteall
67 INPUT_END
69 ) |
70 git fast-import --quiet &&
71 git config core.notesRef refs/notes/commits
74 test_sha1_based () {
76 start_note_commit &&
77 nr=$number_of_commits &&
78 git rev-list refs/heads/master |
79 while read sha1; do
80 note_path=$(echo "$sha1" | sed "$1")
81 cat <<INPUT_END &&
82 M 100644 inline $note_path
83 data <<EOF
84 note for commit #$nr
85 EOF
87 INPUT_END
89 nr=$(($nr-1))
90 done
91 ) |
92 git fast-import --quiet
95 test_expect_success 'test notes in 2/38-fanout' 'test_sha1_based "s|^..|&/|"'
96 test_expect_success 'verify notes in 2/38-fanout' 'verify_notes'
98 test_expect_success 'test notes in 2/2/36-fanout' 'test_sha1_based "s|^\(..\)\(..\)|\1/\2/|"'
99 test_expect_success 'verify notes in 2/2/36-fanout' 'verify_notes'
101 test_expect_success 'test notes in 2/2/2/34-fanout' 'test_sha1_based "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
102 test_expect_success 'verify notes in 2/2/2/34-fanout' 'verify_notes'
104 test_same_notes () {
106 start_note_commit &&
107 nr=$number_of_commits &&
108 git rev-list refs/heads/master |
109 while read sha1; do
110 first_note_path=$(echo "$sha1" | sed "$1")
111 second_note_path=$(echo "$sha1" | sed "$2")
112 cat <<INPUT_END &&
113 M 100644 inline $second_note_path
114 data <<EOF
115 note for commit #$nr
118 M 100644 inline $first_note_path
119 data <<EOF
120 note for commit #$nr
123 INPUT_END
125 nr=$(($nr-1))
126 done
128 git fast-import --quiet
131 test_expect_success 'test same notes in no fanout and 2/38-fanout' 'test_same_notes "s|^..|&/|" ""'
132 test_expect_success 'verify same notes in no fanout and 2/38-fanout' 'verify_notes'
134 test_expect_success 'test same notes in no fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
135 test_expect_success 'verify same notes in no fanout and 2/2/36-fanout' 'verify_notes'
137 test_expect_success 'test same notes in 2/38-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
138 test_expect_success 'verify same notes in 2/38-fanout and 2/2/36-fanout' 'verify_notes'
140 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/|"'
141 test_expect_success 'verify same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'verify_notes'
143 test_concatenated_notes () {
145 start_note_commit &&
146 nr=$number_of_commits &&
147 git rev-list refs/heads/master |
148 while read sha1; do
149 first_note_path=$(echo "$sha1" | sed "$1")
150 second_note_path=$(echo "$sha1" | sed "$2")
151 cat <<INPUT_END &&
152 M 100644 inline $second_note_path
153 data <<EOF
154 second note for commit #$nr
157 M 100644 inline $first_note_path
158 data <<EOF
159 first note for commit #$nr
162 INPUT_END
164 nr=$(($nr-1))
165 done
167 git fast-import --quiet
170 verify_concatenated_notes () {
171 git log | grep "^ " > output &&
172 i=$number_of_commits &&
173 while [ $i -gt 0 ]; do
174 echo " commit #$i" &&
175 echo " first note for commit #$i" &&
176 echo " " &&
177 echo " second note for commit #$i" &&
178 i=$(($i-1));
179 done > expect &&
180 test_cmp expect output
183 test_expect_success 'test notes in no fanout concatenated with 2/38-fanout' 'test_concatenated_notes "s|^..|&/|" ""'
184 test_expect_success 'verify notes in no fanout concatenated with 2/38-fanout' 'verify_concatenated_notes'
186 test_expect_success 'test notes in no fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
187 test_expect_success 'verify notes in no fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
189 test_expect_success 'test notes in 2/38-fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
190 test_expect_success 'verify notes in 2/38-fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
192 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/|"'
193 test_expect_success 'verify notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'verify_concatenated_notes'
195 test_done