Merge branch 'rj/cygwin-has-dev-tty'
[git/gitster.git] / t / t3306-notes-prune.sh
blobb6e9f643e3cd8d4a81d63e721c5a16390b879e05
1 #!/bin/sh
3 test_description='Test git notes prune'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup: create a few commits with notes' '
10 : > file1 &&
11 git add file1 &&
12 test_tick &&
13 git commit -m 1st &&
14 git notes add -m "Note #1" &&
15 first=$(git rev-parse HEAD) &&
16 : > file2 &&
17 git add file2 &&
18 test_tick &&
19 git commit -m 2nd &&
20 git notes add -m "Note #2" &&
21 second=$(git rev-parse HEAD) &&
22 : > file3 &&
23 git add file3 &&
24 test_tick &&
25 git commit -m 3rd &&
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
34 commit $third
35 Author: A U Thor <author@example.com>
36 Date: Thu Apr 7 15:15:13 2005 -0700
38 3rd
40 Notes:
41 Note #3
43 commit $second
44 Author: A U Thor <author@example.com>
45 Date: Thu Apr 7 15:14:13 2005 -0700
47 2nd
49 Notes:
50 Note #2
52 commit $first
53 Author: A U Thor <author@example.com>
54 Date: Thu Apr 7 15:13:13 2005 -0700
56 1st
58 Notes:
59 Note #1
60 END_OF_LOG
62 test_expect_success 'verify commits and notes' '
64 git log > actual &&
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 &&
72 git gc --prune=now
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 &&
86 git notes show $first
89 test_expect_success 'prune -n does not remove notes' '
91 git notes list > expect &&
92 git notes prune -n &&
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' '
108 git notes prune
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 &&
122 git gc --prune=now
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
139 test_done