3 test_description
='Test git notes prune'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'setup: create a few commits with notes' '
14 git notes add -m "Note #1" &&
15 first=$(git rev-parse HEAD) &&
20 git notes add -m "Note #2" &&
21 second=$(git rev-parse HEAD) &&
26 third=$(git rev-parse HEAD) &&
27 COMMIT_FILE=$(echo $third | sed "s!^..!.git/objects/&/!") &&
28 test -f $COMMIT_FILE &&
29 test-tool chmtime =+0 $COMMIT_FILE &&
30 git notes add -m "Note #3"
33 cat > expect
<<END_OF_LOG
35 Author: A U Thor <author@example.com>
36 Date: Thu Apr 7 15:15:13 2005 -0700
44 Author: A U Thor <author@example.com>
45 Date: Thu Apr 7 15:14:13 2005 -0700
53 Author: A U Thor <author@example.com>
54 Date: Thu Apr 7 15:13:13 2005 -0700
62 test_expect_success
'verify commits and notes' '
65 test_cmp expect actual
68 test_expect_success
'remove some commits' '
70 git reset --hard HEAD~1 &&
71 git reflog expire --expire=now HEAD &&
75 test_expect_success
'verify that commits are gone' '
77 test_must_fail git cat-file -p $third &&
78 git cat-file -p $second &&
79 git cat-file -p $first
82 test_expect_success
'verify that notes are still present' '
84 git notes show $third &&
85 git notes show $second &&
89 test_expect_success
'prune -n does not remove notes' '
91 git notes list > expect &&
93 git notes list > actual &&
94 test_cmp expect actual
98 test_expect_success
'prune -n lists prunable notes' '
100 echo $third >expect &&
101 git notes prune -n > actual &&
102 test_cmp expect actual
106 test_expect_success
'prune notes' '
111 test_expect_success
'verify that notes are gone' '
113 test_must_fail git notes show $third &&
114 git notes show $second &&
115 git notes show $first
118 test_expect_success
'remove some commits' '
120 git reset --hard HEAD~1 &&
121 git reflog expire --expire=now HEAD &&
125 test_expect_success
'prune -v notes' '
127 echo $second >expect &&
128 git notes prune -v > actual &&
129 test_cmp expect actual
132 test_expect_success
'verify that notes are gone' '
134 test_must_fail git notes show $third &&
135 test_must_fail git notes show $second &&
136 git notes show $first