Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test git notes prune' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_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 Herland | aaec9bc | 2010-02-13 22:28:34 +0100 | [diff] [blame] | 13 | git notes add -m "Note #1" && |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 14 | first=$(git rev-parse HEAD) && |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 15 | : > file2 && |
| 16 | git add file2 && |
| 17 | test_tick && |
| 18 | git commit -m 2nd && |
Johan Herland | aaec9bc | 2010-02-13 22:28:34 +0100 | [diff] [blame] | 19 | git notes add -m "Note #2" && |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 20 | second=$(git rev-parse HEAD) && |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 21 | : > file3 && |
| 22 | git add file3 && |
| 23 | test_tick && |
| 24 | git commit -m 3rd && |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 25 | third=$(git rev-parse HEAD) && |
| 26 | COMMIT_FILE=$(echo $third | sed "s!^..!.git/objects/&/!") && |
Michael J Gruber | e3b02bc | 2011-04-14 19:38:13 +0200 | [diff] [blame] | 27 | test -f $COMMIT_FILE && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 28 | test-tool chmtime =+0 $COMMIT_FILE && |
Johan Herland | aaec9bc | 2010-02-13 22:28:34 +0100 | [diff] [blame] | 29 | git notes add -m "Note #3" |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 30 | ' |
| 31 | |
| 32 | cat > expect <<END_OF_LOG |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 33 | commit $third |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 34 | Author: A U Thor <author@example.com> |
| 35 | Date: Thu Apr 7 15:15:13 2005 -0700 |
| 36 | |
| 37 | 3rd |
| 38 | |
| 39 | Notes: |
| 40 | Note #3 |
| 41 | |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 42 | commit $second |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 43 | Author: A U Thor <author@example.com> |
| 44 | Date: Thu Apr 7 15:14:13 2005 -0700 |
| 45 | |
| 46 | 2nd |
| 47 | |
| 48 | Notes: |
| 49 | Note #2 |
| 50 | |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 51 | commit $first |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 52 | Author: A U Thor <author@example.com> |
| 53 | Date: Thu Apr 7 15:13:13 2005 -0700 |
| 54 | |
| 55 | 1st |
| 56 | |
| 57 | Notes: |
| 58 | Note #1 |
| 59 | END_OF_LOG |
| 60 | |
| 61 | test_expect_success 'verify commits and notes' ' |
| 62 | |
| 63 | git log > actual && |
| 64 | test_cmp expect actual |
| 65 | ' |
| 66 | |
| 67 | test_expect_success 'remove some commits' ' |
| 68 | |
Michael J Gruber | a9f2adf | 2010-05-14 23:42:07 +0200 | [diff] [blame] | 69 | git reset --hard HEAD~1 && |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 70 | git reflog expire --expire=now HEAD && |
| 71 | git gc --prune=now |
| 72 | ' |
| 73 | |
| 74 | test_expect_success 'verify that commits are gone' ' |
| 75 | |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 76 | test_must_fail git cat-file -p $third && |
| 77 | git cat-file -p $second && |
| 78 | git cat-file -p $first |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 79 | ' |
| 80 | |
| 81 | test_expect_success 'verify that notes are still present' ' |
| 82 | |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 83 | git notes show $third && |
| 84 | git notes show $second && |
| 85 | git notes show $first |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 86 | ' |
| 87 | |
Michael J Gruber | a9f2adf | 2010-05-14 23:42:07 +0200 | [diff] [blame] | 88 | test_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 Gruber | a9f2adf | 2010-05-14 23:42:07 +0200 | [diff] [blame] | 96 | |
| 97 | test_expect_success 'prune -n lists prunable notes' ' |
| 98 | |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 99 | echo $third >expect && |
Michael J Gruber | a9f2adf | 2010-05-14 23:42:07 +0200 | [diff] [blame] | 100 | git notes prune -n > actual && |
| 101 | test_cmp expect actual |
| 102 | ' |
| 103 | |
| 104 | |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 105 | test_expect_success 'prune notes' ' |
| 106 | |
| 107 | git notes prune |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'verify that notes are gone' ' |
| 111 | |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 112 | test_must_fail git notes show $third && |
| 113 | git notes show $second && |
| 114 | git notes show $first |
Michael J Gruber | a9f2adf | 2010-05-14 23:42:07 +0200 | [diff] [blame] | 115 | ' |
| 116 | |
| 117 | test_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 Gruber | a9f2adf | 2010-05-14 23:42:07 +0200 | [diff] [blame] | 124 | test_expect_success 'prune -v notes' ' |
| 125 | |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 126 | echo $second >expect && |
Michael J Gruber | a9f2adf | 2010-05-14 23:42:07 +0200 | [diff] [blame] | 127 | git notes prune -v > actual && |
| 128 | test_cmp expect actual |
| 129 | ' |
| 130 | |
| 131 | test_expect_success 'verify that notes are gone' ' |
| 132 | |
brian m. carlson | b99bfc7 | 2019-08-18 19:16:37 +0000 | [diff] [blame] | 133 | test_must_fail git notes show $third && |
| 134 | test_must_fail git notes show $second && |
| 135 | git notes show $first |
Johan Herland | d6576e1 | 2010-02-13 22:28:28 +0100 | [diff] [blame] | 136 | ' |
| 137 | |
| 138 | test_done |