Merge branch 'rr/push-head' into maint
[git/mjg.git] / t / t3306-notes-prune.sh
blob86bf909ee3dfca78f678fdefe961772dcd78d6b1
1 #!/bin/sh
3 test_description='Test git notes prune'
5 . ./test-lib.sh
7 test_expect_success 'setup: create a few commits with notes' '
9 : > file1 &&
10 git add file1 &&
11 test_tick &&
12 git commit -m 1st &&
13 git notes add -m "Note #1" &&
14 : > file2 &&
15 git add file2 &&
16 test_tick &&
17 git commit -m 2nd &&
18 git notes add -m "Note #2" &&
19 : > file3 &&
20 git add file3 &&
21 test_tick &&
22 git commit -m 3rd &&
23 COMMIT_FILE=.git/objects/5e/e1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
24 test -f $COMMIT_FILE &&
25 test-chmtime =+0 $COMMIT_FILE &&
26 git notes add -m "Note #3"
29 cat > expect <<END_OF_LOG
30 commit 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
31 Author: A U Thor <author@example.com>
32 Date: Thu Apr 7 15:15:13 2005 -0700
34 3rd
36 Notes:
37 Note #3
39 commit 08341ad9e94faa089d60fd3f523affb25c6da189
40 Author: A U Thor <author@example.com>
41 Date: Thu Apr 7 15:14:13 2005 -0700
43 2nd
45 Notes:
46 Note #2
48 commit ab5f302035f2e7aaf04265f08b42034c23256e1f
49 Author: A U Thor <author@example.com>
50 Date: Thu Apr 7 15:13:13 2005 -0700
52 1st
54 Notes:
55 Note #1
56 END_OF_LOG
58 test_expect_success 'verify commits and notes' '
60 git log > actual &&
61 test_cmp expect actual
64 test_expect_success 'remove some commits' '
66 git reset --hard HEAD~1 &&
67 git reflog expire --expire=now HEAD &&
68 git gc --prune=now
71 test_expect_success 'verify that commits are gone' '
73 test_must_fail git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
74 git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
75 git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
78 test_expect_success 'verify that notes are still present' '
80 git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
81 git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
82 git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
85 test_expect_success 'prune -n does not remove notes' '
87 git notes list > expect &&
88 git notes prune -n &&
89 git notes list > actual &&
90 test_cmp expect actual
93 cat > expect <<EOF
94 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
95 EOF
97 test_expect_success 'prune -n lists prunable notes' '
100 git notes prune -n > actual &&
101 test_cmp expect actual
105 test_expect_success 'prune notes' '
107 git notes prune
110 test_expect_success 'verify that notes are gone' '
112 test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
113 git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
114 git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
117 test_expect_success 'remove some commits' '
119 git reset --hard HEAD~1 &&
120 git reflog expire --expire=now HEAD &&
121 git gc --prune=now
124 cat > expect <<EOF
125 08341ad9e94faa089d60fd3f523affb25c6da189
128 test_expect_success 'prune -v notes' '
130 git notes prune -v > actual &&
131 test_cmp expect actual
134 test_expect_success 'verify that notes are gone' '
136 test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
137 test_must_fail git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
138 git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
141 test_done