blob: 8f4102ff9e446bce66436b5e7046c84d739c226f [file] [log] [blame]
Johan Herlandd6576e12010-02-13 22:28:28 +01001#!/bin/sh
2
3test_description='Test git notes prune'
4
5. ./test-lib.sh
6
7test_expect_success 'setup: create a few commits with notes' '
8
9 : > file1 &&
10 git add file1 &&
11 test_tick &&
12 git commit -m 1st &&
Johan Herlandaaec9bc2010-02-13 22:28:34 +010013 git notes add -m "Note #1" &&
brian m. carlsonb99bfc72019-08-18 19:16:37 +000014 first=$(git rev-parse HEAD) &&
Johan Herlandd6576e12010-02-13 22:28:28 +010015 : > file2 &&
16 git add file2 &&
17 test_tick &&
18 git commit -m 2nd &&
Johan Herlandaaec9bc2010-02-13 22:28:34 +010019 git notes add -m "Note #2" &&
brian m. carlsonb99bfc72019-08-18 19:16:37 +000020 second=$(git rev-parse HEAD) &&
Johan Herlandd6576e12010-02-13 22:28:28 +010021 : > file3 &&
22 git add file3 &&
23 test_tick &&
24 git commit -m 3rd &&
brian m. carlsonb99bfc72019-08-18 19:16:37 +000025 third=$(git rev-parse HEAD) &&
26 COMMIT_FILE=$(echo $third | sed "s!^..!.git/objects/&/!") &&
Michael J Grubere3b02bc2011-04-14 19:38:13 +020027 test -f $COMMIT_FILE &&
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +010028 test-tool chmtime =+0 $COMMIT_FILE &&
Johan Herlandaaec9bc2010-02-13 22:28:34 +010029 git notes add -m "Note #3"
Johan Herlandd6576e12010-02-13 22:28:28 +010030'
31
32cat > expect <<END_OF_LOG
brian m. carlsonb99bfc72019-08-18 19:16:37 +000033commit $third
Johan Herlandd6576e12010-02-13 22:28:28 +010034Author: A U Thor <author@example.com>
35Date: Thu Apr 7 15:15:13 2005 -0700
36
37 3rd
38
39Notes:
40 Note #3
41
brian m. carlsonb99bfc72019-08-18 19:16:37 +000042commit $second
Johan Herlandd6576e12010-02-13 22:28:28 +010043Author: A U Thor <author@example.com>
44Date: Thu Apr 7 15:14:13 2005 -0700
45
46 2nd
47
48Notes:
49 Note #2
50
brian m. carlsonb99bfc72019-08-18 19:16:37 +000051commit $first
Johan Herlandd6576e12010-02-13 22:28:28 +010052Author: A U Thor <author@example.com>
53Date: Thu Apr 7 15:13:13 2005 -0700
54
55 1st
56
57Notes:
58 Note #1
59END_OF_LOG
60
61test_expect_success 'verify commits and notes' '
62
63 git log > actual &&
64 test_cmp expect actual
65'
66
67test_expect_success 'remove some commits' '
68
Michael J Grubera9f2adf2010-05-14 23:42:07 +020069 git reset --hard HEAD~1 &&
Johan Herlandd6576e12010-02-13 22:28:28 +010070 git reflog expire --expire=now HEAD &&
71 git gc --prune=now
72'
73
74test_expect_success 'verify that commits are gone' '
75
brian m. carlsonb99bfc72019-08-18 19:16:37 +000076 test_must_fail git cat-file -p $third &&
77 git cat-file -p $second &&
78 git cat-file -p $first
Johan Herlandd6576e12010-02-13 22:28:28 +010079'
80
81test_expect_success 'verify that notes are still present' '
82
brian m. carlsonb99bfc72019-08-18 19:16:37 +000083 git notes show $third &&
84 git notes show $second &&
85 git notes show $first
Johan Herlandd6576e12010-02-13 22:28:28 +010086'
87
Michael J Grubera9f2adf2010-05-14 23:42:07 +020088test_expect_success 'prune -n does not remove notes' '
89
90 git notes list > expect &&
91 git notes prune -n &&
92 git notes list > actual &&
93 test_cmp expect actual
94'
95
Michael J Grubera9f2adf2010-05-14 23:42:07 +020096
97test_expect_success 'prune -n lists prunable notes' '
98
brian m. carlsonb99bfc72019-08-18 19:16:37 +000099 echo $third >expect &&
Michael J Grubera9f2adf2010-05-14 23:42:07 +0200100 git notes prune -n > actual &&
101 test_cmp expect actual
102'
103
104
Johan Herlandd6576e12010-02-13 22:28:28 +0100105test_expect_success 'prune notes' '
106
107 git notes prune
108'
109
110test_expect_success 'verify that notes are gone' '
111
brian m. carlsonb99bfc72019-08-18 19:16:37 +0000112 test_must_fail git notes show $third &&
113 git notes show $second &&
114 git notes show $first
Michael J Grubera9f2adf2010-05-14 23:42:07 +0200115'
116
117test_expect_success 'remove some commits' '
118
119 git reset --hard HEAD~1 &&
120 git reflog expire --expire=now HEAD &&
121 git gc --prune=now
122'
123
Michael J Grubera9f2adf2010-05-14 23:42:07 +0200124test_expect_success 'prune -v notes' '
125
brian m. carlsonb99bfc72019-08-18 19:16:37 +0000126 echo $second >expect &&
Michael J Grubera9f2adf2010-05-14 23:42:07 +0200127 git notes prune -v > actual &&
128 test_cmp expect actual
129'
130
131test_expect_success 'verify that notes are gone' '
132
brian m. carlsonb99bfc72019-08-18 19:16:37 +0000133 test_must_fail git notes show $third &&
134 test_must_fail git notes show $second &&
135 git notes show $first
Johan Herlandd6576e12010-02-13 22:28:28 +0100136'
137
138test_done