test-ctype: check EOF
[git.git] / t / t3304-notes-mixed.sh
blob2c3a2452668c514ce40c107537cc4e0c1abe5312
1 #!/bin/sh
3 test_description='Test notes trees that also contain non-notes'
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));
35 done > expect &&
36 test_cmp expect output
39 test_expect_success "setup: create a couple of commits" '
41 test_tick &&
42 cat <<INPUT_END >input &&
43 commit refs/heads/main
44 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
45 data <<COMMIT
46 commit #1
47 COMMIT
49 M 644 inline file
50 data <<EOF
51 file in commit #1
52 EOF
54 INPUT_END
56 test_tick &&
57 cat <<INPUT_END >>input &&
58 commit refs/heads/main
59 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
60 data <<COMMIT
61 commit #2
62 COMMIT
64 M 644 inline file
65 data <<EOF
66 file in commit #2
67 EOF
69 INPUT_END
70 git fast-import --quiet <input
73 test_expect_success "create a notes tree with both notes and non-notes" '
75 commit1=$(git rev-parse refs/heads/main^) &&
76 commit2=$(git rev-parse refs/heads/main) &&
77 test_tick &&
78 cat <<INPUT_END >input &&
79 commit refs/notes/commits
80 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
81 data <<COMMIT
82 notes commit #1
83 COMMIT
85 N inline $commit1
86 data <<EOF
87 note for commit #1
88 EOF
90 N inline $commit2
91 data <<EOF
92 note for commit #2
93 EOF
95 INPUT_END
96 test_tick &&
97 cat <<INPUT_END >>input &&
98 commit refs/notes/commits
99 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
100 data <<COMMIT
101 notes commit #2
102 COMMIT
104 M 644 inline foobar/non-note.txt
105 data <<EOF
106 A non-note in a notes tree
109 N inline $commit2
110 data <<EOF
111 edited note for commit #2
114 INPUT_END
115 test_tick &&
116 cat <<INPUT_END >>input &&
117 commit refs/notes/commits
118 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
119 data <<COMMIT
120 notes commit #3
121 COMMIT
123 N inline $commit1
124 data <<EOF
125 edited note for commit #1
128 M 644 inline deadbeef
129 data <<EOF
130 non-note with SHA1-like name
133 M 644 inline de/adbeef
134 data <<EOF
135 another non-note with SHA1-like name
138 M 644 inline de/adbeefdeadbeefdeadbeefdeadbeefdeadbeef
139 data <<EOF
140 This is actually a valid note, albeit to a non-existing object.
141 It is needed in order to trigger the "mishandling" of the dead/beef non-note.
144 M 644 inline dead/beef
145 data <<EOF
146 yet another non-note with SHA1-like name
149 INPUT_END
150 git fast-import --quiet <input &&
151 git config core.notesRef refs/notes/commits
154 cat >expect <<EXPECT_END
155 commit #2
156 edited note for commit #2
157 commit #1
158 edited note for commit #1
159 EXPECT_END
161 test_expect_success "verify contents of notes" '
163 git log | grep "^ " > actual &&
164 test_cmp expect actual
167 cat >expect_nn1 <<EXPECT_END
168 A non-note in a notes tree
169 EXPECT_END
170 cat >expect_nn2 <<EXPECT_END
171 non-note with SHA1-like name
172 EXPECT_END
173 cat >expect_nn3 <<EXPECT_END
174 another non-note with SHA1-like name
175 EXPECT_END
176 cat >expect_nn4 <<EXPECT_END
177 yet another non-note with SHA1-like name
178 EXPECT_END
180 test_expect_success "verify contents of non-notes" '
182 git cat-file -p refs/notes/commits:foobar/non-note.txt > actual_nn1 &&
183 test_cmp expect_nn1 actual_nn1 &&
184 git cat-file -p refs/notes/commits:deadbeef > actual_nn2 &&
185 test_cmp expect_nn2 actual_nn2 &&
186 git cat-file -p refs/notes/commits:de/adbeef > actual_nn3 &&
187 test_cmp expect_nn3 actual_nn3 &&
188 git cat-file -p refs/notes/commits:dead/beef > actual_nn4 &&
189 test_cmp expect_nn4 actual_nn4
192 test_expect_success "git-notes preserves non-notes" '
194 test_tick &&
195 git notes add -f -m "foo bar"
198 test_expect_success "verify contents of non-notes after git-notes" '
200 git cat-file -p refs/notes/commits:foobar/non-note.txt > actual_nn1 &&
201 test_cmp expect_nn1 actual_nn1 &&
202 git cat-file -p refs/notes/commits:deadbeef > actual_nn2 &&
203 test_cmp expect_nn2 actual_nn2 &&
204 git cat-file -p refs/notes/commits:de/adbeef > actual_nn3 &&
205 test_cmp expect_nn3 actual_nn3 &&
206 git cat-file -p refs/notes/commits:dead/beef > actual_nn4 &&
207 test_cmp expect_nn4 actual_nn4
210 test_done