Merge branch 'ao/send-email-irt'
[git/kirr.git] / t / t3304-notes-mixed.sh
blob1709e8c00b859ae4f8ce91c7920a9411ac4acbce
1 #!/bin/sh
3 test_description='Test notes trees that also contain non-notes'
5 . ./test-lib.sh
7 number_of_commits=100
9 start_note_commit () {
10 test_tick &&
11 cat <<INPUT_END
12 commit refs/notes/commits
13 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
14 data <<COMMIT
15 notes
16 COMMIT
18 from refs/notes/commits^0
19 deleteall
20 INPUT_END
24 verify_notes () {
25 git log | grep "^ " > output &&
26 i=$number_of_commits &&
27 while [ $i -gt 0 ]; do
28 echo " commit #$i" &&
29 echo " note for commit #$i" &&
30 i=$(($i-1));
31 done > expect &&
32 test_cmp expect output
35 test_expect_success "setup: create a couple of commits" '
37 test_tick &&
38 cat <<INPUT_END >input &&
39 commit refs/heads/master
40 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
41 data <<COMMIT
42 commit #1
43 COMMIT
45 M 644 inline file
46 data <<EOF
47 file in commit #1
48 EOF
50 INPUT_END
52 test_tick &&
53 cat <<INPUT_END >>input &&
54 commit refs/heads/master
55 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
56 data <<COMMIT
57 commit #2
58 COMMIT
60 M 644 inline file
61 data <<EOF
62 file in commit #2
63 EOF
65 INPUT_END
66 git fast-import --quiet <input
69 test_expect_success "create a notes tree with both notes and non-notes" '
71 commit1=$(git rev-parse refs/heads/master^) &&
72 commit2=$(git rev-parse refs/heads/master) &&
73 test_tick &&
74 cat <<INPUT_END >input &&
75 commit refs/notes/commits
76 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
77 data <<COMMIT
78 notes commit #1
79 COMMIT
81 N inline $commit1
82 data <<EOF
83 note for commit #1
84 EOF
86 N inline $commit2
87 data <<EOF
88 note for commit #2
89 EOF
91 INPUT_END
92 test_tick &&
93 cat <<INPUT_END >>input &&
94 commit refs/notes/commits
95 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
96 data <<COMMIT
97 notes commit #2
98 COMMIT
100 M 644 inline foobar/non-note.txt
101 data <<EOF
102 A non-note in a notes tree
105 N inline $commit2
106 data <<EOF
107 edited note for commit #2
110 INPUT_END
111 test_tick &&
112 cat <<INPUT_END >>input &&
113 commit refs/notes/commits
114 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
115 data <<COMMIT
116 notes commit #3
117 COMMIT
119 N inline $commit1
120 data <<EOF
121 edited note for commit #1
124 M 644 inline deadbeef
125 data <<EOF
126 non-note with SHA1-like name
129 M 644 inline de/adbeef
130 data <<EOF
131 another non-note with SHA1-like name
134 M 644 inline de/adbeefdeadbeefdeadbeefdeadbeefdeadbeef
135 data <<EOF
136 This is actually a valid note, albeit to a non-existing object.
137 It is needed in order to trigger the "mishandling" of the dead/beef non-note.
140 M 644 inline dead/beef
141 data <<EOF
142 yet another non-note with SHA1-like name
145 INPUT_END
146 git fast-import --quiet <input &&
147 git config core.notesRef refs/notes/commits
150 cat >expect <<EXPECT_END
151 commit #2
152 edited note for commit #2
153 commit #1
154 edited note for commit #1
155 EXPECT_END
157 test_expect_success "verify contents of notes" '
159 git log | grep "^ " > actual &&
160 test_cmp expect actual
163 cat >expect_nn1 <<EXPECT_END
164 A non-note in a notes tree
165 EXPECT_END
166 cat >expect_nn2 <<EXPECT_END
167 non-note with SHA1-like name
168 EXPECT_END
169 cat >expect_nn3 <<EXPECT_END
170 another non-note with SHA1-like name
171 EXPECT_END
172 cat >expect_nn4 <<EXPECT_END
173 yet another non-note with SHA1-like name
174 EXPECT_END
176 test_expect_success "verify contents of non-notes" '
178 git cat-file -p refs/notes/commits:foobar/non-note.txt > actual_nn1 &&
179 test_cmp expect_nn1 actual_nn1 &&
180 git cat-file -p refs/notes/commits:deadbeef > actual_nn2 &&
181 test_cmp expect_nn2 actual_nn2 &&
182 git cat-file -p refs/notes/commits:de/adbeef > actual_nn3 &&
183 test_cmp expect_nn3 actual_nn3 &&
184 git cat-file -p refs/notes/commits:dead/beef > actual_nn4 &&
185 test_cmp expect_nn4 actual_nn4
188 test_expect_success "git-notes preserves non-notes" '
190 test_tick &&
191 git notes add -f -m "foo bar"
194 test_expect_success "verify contents of non-notes after git-notes" '
196 git cat-file -p refs/notes/commits:foobar/non-note.txt > actual_nn1 &&
197 test_cmp expect_nn1 actual_nn1 &&
198 git cat-file -p refs/notes/commits:deadbeef > actual_nn2 &&
199 test_cmp expect_nn2 actual_nn2 &&
200 git cat-file -p refs/notes/commits:de/adbeef > actual_nn3 &&
201 test_cmp expect_nn3 actual_nn3 &&
202 git cat-file -p refs/notes/commits:dead/beef > actual_nn4 &&
203 test_cmp expect_nn4 actual_nn4
206 test_done