]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3304-notes-mixed.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t3304-notes-mixed.sh
1 #!/bin/sh
2
3 test_description='Test notes trees that also contain non-notes'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 number_of_commits=100
12
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
21
22 from refs/notes/commits^0
23 deleteall
24 INPUT_END
25
26 }
27
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
37 }
38
39 test_expect_success "setup: create a couple of commits" '
40
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
48
49 M 644 inline file
50 data <<EOF
51 file in commit #1
52 EOF
53
54 INPUT_END
55
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
63
64 M 644 inline file
65 data <<EOF
66 file in commit #2
67 EOF
68
69 INPUT_END
70 git fast-import --quiet <input
71 '
72
73 test_expect_success "create a notes tree with both notes and non-notes" '
74
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
84
85 N inline $commit1
86 data <<EOF
87 note for commit #1
88 EOF
89
90 N inline $commit2
91 data <<EOF
92 note for commit #2
93 EOF
94
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
103
104 M 644 inline foobar/non-note.txt
105 data <<EOF
106 A non-note in a notes tree
107 EOF
108
109 N inline $commit2
110 data <<EOF
111 edited note for commit #2
112 EOF
113
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
122
123 N inline $commit1
124 data <<EOF
125 edited note for commit #1
126 EOF
127
128 M 644 inline deadbeef
129 data <<EOF
130 non-note with SHA1-like name
131 EOF
132
133 M 644 inline de/adbeef
134 data <<EOF
135 another non-note with SHA1-like name
136 EOF
137
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.
142 EOF
143
144 M 644 inline dead/beef
145 data <<EOF
146 yet another non-note with SHA1-like name
147 EOF
148
149 INPUT_END
150 git fast-import --quiet <input &&
151 git config core.notesRef refs/notes/commits
152 '
153
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
160
161 test_expect_success "verify contents of notes" '
162
163 git log | grep "^ " > actual &&
164 test_cmp expect actual
165 '
166
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
179
180 test_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 &&
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
192 test_expect_success "git-notes preserves non-notes" '
193
194 test_tick &&
195 git notes add -f -m "foo bar"
196 '
197
198 test_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
208 '
209
210 test_done