]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3304-notes-mixed.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t3304-notes-mixed.sh
CommitLineData
488bdf2e
JH
1#!/bin/sh
2
3test_description='Test notes trees that also contain non-notes'
4
d6c6b108 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
27472b51 8TEST_PASSES_SANITIZE_LEAK=true
488bdf2e
JH
9. ./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 &&
d6c6b108 43commit refs/heads/main
488bdf2e
JH
44committer $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 &&
d6c6b108 58commit refs/heads/main
488bdf2e
JH
59committer $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
d6c6b108
JS
75 commit1=$(git rev-parse refs/heads/main^) &&
76 commit2=$(git rev-parse refs/heads/main) &&
488bdf2e
JH
77 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
851c2b37
JH
138M 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
488bdf2e
JH
149INPUT_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
851c2b37
JH
176cat >expect_nn4 <<EXPECT_END
177yet another non-note with SHA1-like name
178EXPECT_END
488bdf2e
JH
179
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 &&
851c2b37
JH
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
190'
191
192test_expect_success "git-notes preserves non-notes" '
193
194 test_tick &&
aaec9bcf 195 git notes add -f -m "foo bar"
851c2b37
JH
196'
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
488bdf2e
JH
208'
209
210test_done