blob: 2c3a2452668c514ce40c107537cc4e0c1abe5312 [file] [log] [blame]
Johan Herland488bdf22009-12-03 04:53:54 +01001#!/bin/sh
2
3test_description='Test notes trees that also contain non-notes'
4
Johannes Schindelind6c6b102020-11-18 23:44:23 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Ævar Arnfjörð Bjarmason27472b52022-07-01 12:42:59 +02008TEST_PASSES_SANITIZE_LEAK=true
Johan Herland488bdf22009-12-03 04:53:54 +01009. ./test-lib.sh
10
11number_of_commits=100
12
13start_note_commit () {
14 test_tick &&
15 cat <<INPUT_END
16commit refs/notes/commits
17committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
18data <<COMMIT
19notes
20COMMIT
21
22from refs/notes/commits^0
23deleteall
24INPUT_END
25
26}
27
28verify_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
37}
38
39test_expect_success "setup: create a couple of commits" '
40
41 test_tick &&
42 cat <<INPUT_END >input &&
Johannes Schindelind6c6b102020-11-18 23:44:23 +000043commit refs/heads/main
Johan Herland488bdf22009-12-03 04:53:54 +010044committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
45data <<COMMIT
46commit #1
47COMMIT
48
49M 644 inline file
50data <<EOF
51file in commit #1
52EOF
53
54INPUT_END
55
56 test_tick &&
57 cat <<INPUT_END >>input &&
Johannes Schindelind6c6b102020-11-18 23:44:23 +000058commit refs/heads/main
Johan Herland488bdf22009-12-03 04:53:54 +010059committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
60data <<COMMIT
61commit #2
62COMMIT
63
64M 644 inline file
65data <<EOF
66file in commit #2
67EOF
68
69INPUT_END
70 git fast-import --quiet <input
71'
72
73test_expect_success "create a notes tree with both notes and non-notes" '
74
Johannes Schindelind6c6b102020-11-18 23:44:23 +000075 commit1=$(git rev-parse refs/heads/main^) &&
76 commit2=$(git rev-parse refs/heads/main) &&
Johan Herland488bdf22009-12-03 04:53:54 +010077 test_tick &&
78 cat <<INPUT_END >input &&
79commit refs/notes/commits
80committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
81data <<COMMIT
82notes commit #1
83COMMIT
84
85N inline $commit1
86data <<EOF
87note for commit #1
88EOF
89
90N inline $commit2
91data <<EOF
92note for commit #2
93EOF
94
95INPUT_END
96 test_tick &&
97 cat <<INPUT_END >>input &&
98commit refs/notes/commits
99committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
100data <<COMMIT
101notes commit #2
102COMMIT
103
104M 644 inline foobar/non-note.txt
105data <<EOF
106A non-note in a notes tree
107EOF
108
109N inline $commit2
110data <<EOF
111edited note for commit #2
112EOF
113
114INPUT_END
115 test_tick &&
116 cat <<INPUT_END >>input &&
117commit refs/notes/commits
118committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
119data <<COMMIT
120notes commit #3
121COMMIT
122
123N inline $commit1
124data <<EOF
125edited note for commit #1
126EOF
127
128M 644 inline deadbeef
129data <<EOF
130non-note with SHA1-like name
131EOF
132
133M 644 inline de/adbeef
134data <<EOF
135another non-note with SHA1-like name
136EOF
137
Johan Herland851c2b32010-02-13 22:28:23 +0100138M 644 inline de/adbeefdeadbeefdeadbeefdeadbeefdeadbeef
139data <<EOF
140This is actually a valid note, albeit to a non-existing object.
141It is needed in order to trigger the "mishandling" of the dead/beef non-note.
142EOF
143
144M 644 inline dead/beef
145data <<EOF
146yet another non-note with SHA1-like name
147EOF
148
Johan Herland488bdf22009-12-03 04:53:54 +0100149INPUT_END
150 git fast-import --quiet <input &&
151 git config core.notesRef refs/notes/commits
152'
153
154cat >expect <<EXPECT_END
155 commit #2
156 edited note for commit #2
157 commit #1
158 edited note for commit #1
159EXPECT_END
160
161test_expect_success "verify contents of notes" '
162
163 git log | grep "^ " > actual &&
164 test_cmp expect actual
165'
166
167cat >expect_nn1 <<EXPECT_END
168A non-note in a notes tree
169EXPECT_END
170cat >expect_nn2 <<EXPECT_END
171non-note with SHA1-like name
172EXPECT_END
173cat >expect_nn3 <<EXPECT_END
174another non-note with SHA1-like name
175EXPECT_END
Johan Herland851c2b32010-02-13 22:28:23 +0100176cat >expect_nn4 <<EXPECT_END
177yet another non-note with SHA1-like name
178EXPECT_END
Johan Herland488bdf22009-12-03 04:53:54 +0100179
180test_expect_success "verify contents of non-notes" '
181
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 &&
Johan Herland851c2b32010-02-13 22:28:23 +0100187 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
190'
191
192test_expect_success "git-notes preserves non-notes" '
193
194 test_tick &&
Johan Herlandaaec9bc2010-02-13 22:28:34 +0100195 git notes add -f -m "foo bar"
Johan Herland851c2b32010-02-13 22:28:23 +0100196'
197
198test_expect_success "verify contents of non-notes after git-notes" '
199
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
Johan Herland488bdf22009-12-03 04:53:54 +0100208'
209
210test_done