Add selftests verifying that we can parse notes trees with various fanouts
Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Oct 9, 2009 at 12:22 UTC
0057c0917d35f9f21e01f2122e7f2b9f169a8b02
1 file changed
+104
t/t3303-notes-subtrees.sh
new
+104
@@ -0,0 +1,104 @@
1
+#!/bin/sh
2
+
3
+test_description='Test commit notes organized in subtrees'
4
+
5
+. ./test-lib.sh
6
+
7
+number_of_commits=100
8
+
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
17
+
18
+from refs/notes/commits^0
19
+deleteall
20
+INPUT_END
21
+
22
+}
23
+
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
33
+}
34
+
35
+test_expect_success "setup: create $number_of_commits commits" '
36
+
37
+ (
38
+ nr=0 &&
39
+ while [ $nr -lt $number_of_commits ]; do
40
+ nr=$(($nr+1)) &&
41
+ test_tick &&
42
+ cat <<INPUT_END
43
+commit refs/heads/master
44
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
45
+data <<COMMIT
46
+commit #$nr
47
+COMMIT
48
+
49
+M 644 inline file
50
+data <<EOF
51
+file in commit #$nr
52
+EOF
53
+
54
+INPUT_END
55
+
56
+ done &&
57
+ test_tick &&
58
+ cat <<INPUT_END
59
+commit refs/notes/commits
60
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
61
+data <<COMMIT
62
+no notes
63
+COMMIT
64
+
65
+deleteall
66
+
67
+INPUT_END
68
+
69
+ ) |
70
+ git fast-import --quiet &&
71
+ git config core.notesRef refs/notes/commits
72
+'
73
+
74
+test_sha1_based () {
75
+ (
76
+ start_note_commit &&
77
+ nr=$number_of_commits &&
78
+ git rev-list refs/heads/master |
79
+ while read sha1; do
80
+ note_path=$(echo "$sha1" | sed "$1")
81
+ cat <<INPUT_END &&
82
+M 100644 inline $note_path
83
+data <<EOF
84
+note for commit #$nr
85
+EOF
86
+
87
+INPUT_END
88
+
89
+ nr=$(($nr-1))
90
+ done
91
+ ) |
92
+ git fast-import --quiet
93
+}
94
+
95
+test_expect_success 'test notes in 2/38-fanout' 'test_sha1_based "s|^..|&/|"'
96
+test_expect_success 'verify notes in 2/38-fanout' 'verify_notes'
97
+
98
+test_expect_success 'test notes in 4/36-fanout' 'test_sha1_based "s|^....|&/|"'
99
+test_expect_success 'verify notes in 4/36-fanout' 'verify_notes'
100
+
101
+test_expect_success 'test notes in 2/2/36-fanout' 'test_sha1_based "s|^\(..\)\(..\)|\1/\2/|"'
102
+test_expect_success 'verify notes in 2/2/36-fanout' 'verify_notes'
103
+
104
+test_done