refs: make repo_dwim_log() accept a NULL oid
[git/debian.git] / t / t3303-notes-subtrees.sh
blobd47ce00f6944951fbc3b9d09ddf701771a13db7d
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-lib.sh
10 number_of_commits=100
12 start_note_commit () {
13 test_tick &&
14 cat <<INPUT_END
15 commit refs/notes/commits
16 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
17 data <<COMMIT
18 notes
19 COMMIT
21 from refs/notes/commits^0
22 deleteall
23 INPUT_END
27 verify_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));
34 done > expect &&
35 test_cmp expect output
38 test_expect_success "setup: create $number_of_commits commits" '
41 nr=0 &&
42 while [ $nr -lt $number_of_commits ]; do
43 nr=$(($nr+1)) &&
44 test_tick &&
45 cat <<INPUT_END
46 commit refs/heads/main
47 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
48 data <<COMMIT
49 commit #$nr
50 COMMIT
52 M 644 inline file
53 data <<EOF
54 file in commit #$nr
55 EOF
57 INPUT_END
59 done &&
60 test_tick &&
61 cat <<INPUT_END
62 commit refs/notes/commits
63 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
64 data <<COMMIT
65 no notes
66 COMMIT
68 deleteall
70 INPUT_END
72 ) |
73 git fast-import --quiet &&
74 git config core.notesRef refs/notes/commits
77 test_sha1_based () {
79 start_note_commit &&
80 nr=$number_of_commits &&
81 git rev-list refs/heads/main |
82 while read sha1; do
83 note_path=$(echo "$sha1" | sed "$1")
84 cat <<INPUT_END &&
85 M 100644 inline $note_path
86 data <<EOF
87 note for commit #$nr
88 EOF
90 INPUT_END
92 nr=$(($nr-1))
93 done
94 ) |
95 git fast-import --quiet
98 test_expect_success 'test notes in 2/38-fanout' 'test_sha1_based "s|^..|&/|"'
99 test_expect_success 'verify notes in 2/38-fanout' 'verify_notes'
101 test_expect_success 'test notes in 2/2/36-fanout' 'test_sha1_based "s|^\(..\)\(..\)|\1/\2/|"'
102 test_expect_success 'verify notes in 2/2/36-fanout' 'verify_notes'
104 test_expect_success 'test notes in 2/2/2/34-fanout' 'test_sha1_based "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
105 test_expect_success 'verify notes in 2/2/2/34-fanout' 'verify_notes'
107 test_same_notes () {
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 &&
116 M 100644 inline $second_note_path
117 data <<EOF
118 note for commit #$nr
121 M 100644 inline $first_note_path
122 data <<EOF
123 note for commit #$nr
126 INPUT_END
128 nr=$(($nr-1))
129 done
131 git fast-import --quiet
134 test_expect_success 'test same notes in no fanout and 2/38-fanout' 'test_same_notes "s|^..|&/|" ""'
135 test_expect_success 'verify same notes in no fanout and 2/38-fanout' 'verify_notes'
137 test_expect_success 'test same notes in no fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
138 test_expect_success 'verify same notes in no fanout and 2/2/36-fanout' 'verify_notes'
140 test_expect_success 'test same notes in 2/38-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
141 test_expect_success 'verify same notes in 2/38-fanout and 2/2/36-fanout' 'verify_notes'
143 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/|"'
144 test_expect_success 'verify same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'verify_notes'
146 test_concatenated_notes () {
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 &&
155 M 100644 inline $second_note_path
156 data <<EOF
157 second note for commit #$nr
160 M 100644 inline $first_note_path
161 data <<EOF
162 first note for commit #$nr
165 INPUT_END
167 nr=$(($nr-1))
168 done
170 git fast-import --quiet
173 verify_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));
182 done > expect &&
183 test_cmp expect output
186 test_expect_success 'test notes in no fanout concatenated with 2/38-fanout' 'test_concatenated_notes "s|^..|&/|" ""'
187 test_expect_success 'verify notes in no fanout concatenated with 2/38-fanout' 'verify_concatenated_notes'
189 test_expect_success 'test notes in no fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
190 test_expect_success 'verify notes in no fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
192 test_expect_success 'test notes in 2/38-fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
193 test_expect_success 'verify notes in 2/38-fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
195 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/|"'
196 test_expect_success 'verify notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'verify_concatenated_notes'
198 test_done