about summary refs log tree commit diff
path: root/t/t3306-notes-prune.sh
blob: 8f4102ff9e446bce66436b5e7046c84d739c226f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh

test_description='Test git notes prune'

. ./test-lib.sh

test_expect_success 'setup: create a few commits with notes' '

	: > file1 &&
	git add file1 &&
	test_tick &&
	git commit -m 1st &&
	git notes add -m "Note #1" &&
	first=$(git rev-parse HEAD) &&
	: > file2 &&
	git add file2 &&
	test_tick &&
	git commit -m 2nd &&
	git notes add -m "Note #2" &&
	second=$(git rev-parse HEAD) &&
	: > file3 &&
	git add file3 &&
	test_tick &&
	git commit -m 3rd &&
	third=$(git rev-parse HEAD) &&
	COMMIT_FILE=$(echo $third | sed "s!^..!.git/objects/&/!") &&
	test -f $COMMIT_FILE &&
	test-tool chmtime =+0 $COMMIT_FILE &&
	git notes add -m "Note #3"
'

cat > expect <<END_OF_LOG
commit $third
Author: A U Thor <author@example.com>
Date:   Thu Apr 7 15:15:13 2005 -0700

    3rd

Notes:
    Note #3

commit $second
Author: A U Thor <author@example.com>
Date:   Thu Apr 7 15:14:13 2005 -0700

    2nd

Notes:
    Note #2

commit $first
Author: A U Thor <author@example.com>
Date:   Thu Apr 7 15:13:13 2005 -0700

    1st

Notes:
    Note #1
END_OF_LOG

test_expect_success 'verify commits and notes' '

	git log > actual &&
	test_cmp expect actual
'

test_expect_success 'remove some commits' '

	git reset --hard HEAD~1 &&
	git reflog expire --expire=now HEAD &&
	git gc --prune=now
'

test_expect_success 'verify that commits are gone' '

	test_must_fail git cat-file -p $third &&
	git cat-file -p $second &&
	git cat-file -p $first
'

test_expect_success 'verify that notes are still present' '

	git notes show $third &&
	git notes show $second &&
	git notes show $first
'

test_expect_success 'prune -n does not remove notes' '

	git notes list > expect &&
	git notes prune -n &&
	git notes list > actual &&
	test_cmp expect actual
'


test_expect_success 'prune -n lists prunable notes' '

	echo $third >expect &&
	git notes prune -n > actual &&
	test_cmp expect actual
'


test_expect_success 'prune notes' '

	git notes prune
'

test_expect_success 'verify that notes are gone' '

	test_must_fail git notes show $third &&
	git notes show $second &&
	git notes show $first
'

test_expect_success 'remove some commits' '

	git reset --hard HEAD~1 &&
	git reflog expire --expire=now HEAD &&
	git gc --prune=now
'

test_expect_success 'prune -v notes' '

	echo $second >expect &&
	git notes prune -v > actual &&
	test_cmp expect actual
'

test_expect_success 'verify that notes are gone' '

	test_must_fail git notes show $third &&
	test_must_fail git notes show $second &&
	git notes show $first
'

test_done