David Steven Tweed | 8464010 | 2008-02-07 02:55:14 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 Johannes E. Schindelin |
| 4 | # |
| 5 | |
| 6 | test_description='prune' |
Johannes Schindelin | 966b4be | 2020-11-18 23:44:29 +0000 | [diff] [blame] | 7 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 8 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 9 | |
David Steven Tweed | 8464010 | 2008-02-07 02:55:14 +0000 | [diff] [blame] | 10 | . ./test-lib.sh |
| 11 | |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 12 | day=$((60*60*24)) |
| 13 | week=$(($day*7)) |
| 14 | |
| 15 | add_blob() { |
| 16 | before=$(git count-objects | sed "s/ .*//") && |
| 17 | BLOB=$(echo aleph_0 | git hash-object -w --stdin) && |
| 18 | BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") && |
Jeff King | 8ad1652 | 2014-10-10 02:11:14 -0400 | [diff] [blame] | 19 | verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 20 | test_path_is_file $BLOB_FILE && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 21 | test-tool chmtime =+0 $BLOB_FILE |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 22 | } |
| 23 | |
David Steven Tweed | 8464010 | 2008-02-07 02:55:14 +0000 | [diff] [blame] | 24 | test_expect_success setup ' |
Han-Wen Nienhuys | 1fa9cf6 | 2021-05-31 16:56:27 +0000 | [diff] [blame] | 25 | >file && |
David Steven Tweed | 8464010 | 2008-02-07 02:55:14 +0000 | [diff] [blame] | 26 | git add file && |
| 27 | test_tick && |
| 28 | git commit -m initial && |
| 29 | git gc |
David Steven Tweed | 8464010 | 2008-02-07 02:55:14 +0000 | [diff] [blame] | 30 | ' |
| 31 | |
| 32 | test_expect_success 'prune stale packs' ' |
David Steven Tweed | 8464010 | 2008-02-07 02:55:14 +0000 | [diff] [blame] | 33 | orig_pack=$(echo .git/objects/pack/*.pack) && |
Han-Wen Nienhuys | 1fa9cf6 | 2021-05-31 16:56:27 +0000 | [diff] [blame] | 34 | >.git/objects/tmp_1.pack && |
| 35 | >.git/objects/tmp_2.pack && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 36 | test-tool chmtime =-86501 .git/objects/tmp_1.pack && |
David Steven Tweed | 8464010 | 2008-02-07 02:55:14 +0000 | [diff] [blame] | 37 | git prune --expire 1.day && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 38 | test_path_is_file $orig_pack && |
| 39 | test_path_is_file .git/objects/tmp_2.pack && |
| 40 | test_path_is_missing .git/objects/tmp_1.pack |
David Steven Tweed | 8464010 | 2008-02-07 02:55:14 +0000 | [diff] [blame] | 41 | ' |
| 42 | |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 43 | test_expect_success 'prune --expire' ' |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 44 | add_blob && |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 45 | git prune --expire=1.hour.ago && |
Jeff King | 8ad1652 | 2014-10-10 02:11:14 -0400 | [diff] [blame] | 46 | verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 47 | test_path_is_file $BLOB_FILE && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 48 | test-tool chmtime =-86500 $BLOB_FILE && |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 49 | git prune --expire 1.day && |
Jeff King | 8ad1652 | 2014-10-10 02:11:14 -0400 | [diff] [blame] | 50 | verbose test $before = $(git count-objects | sed "s/ .*//") && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 51 | test_path_is_missing $BLOB_FILE |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 52 | ' |
| 53 | |
| 54 | test_expect_success 'gc: implicit prune --expire' ' |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 55 | add_blob && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 56 | test-tool chmtime =-$((2*$week-30)) $BLOB_FILE && |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 57 | git gc && |
Jeff King | 8ad1652 | 2014-10-10 02:11:14 -0400 | [diff] [blame] | 58 | verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 59 | test_path_is_file $BLOB_FILE && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 60 | test-tool chmtime =-$((2*$week+1)) $BLOB_FILE && |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 61 | git gc && |
Jeff King | 8ad1652 | 2014-10-10 02:11:14 -0400 | [diff] [blame] | 62 | verbose test $before = $(git count-objects | sed "s/ .*//") && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 63 | test_path_is_missing $BLOB_FILE |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 64 | ' |
| 65 | |
| 66 | test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' ' |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 67 | git config gc.pruneExpire invalid && |
| 68 | test_must_fail git gc |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 69 | ' |
| 70 | |
| 71 | test_expect_success 'gc: start with ok gc.pruneExpire' ' |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 72 | git config gc.pruneExpire 2.days.ago && |
| 73 | git gc |
Johannes Schindelin | 25ee973 | 2008-03-12 21:55:47 +0100 | [diff] [blame] | 74 | ' |
| 75 | |
Michele Ballabio | 0c62705 | 2008-03-23 22:34:34 +0100 | [diff] [blame] | 76 | test_expect_success 'prune: prune nonsense parameters' ' |
Michele Ballabio | 0c62705 | 2008-03-23 22:34:34 +0100 | [diff] [blame] | 77 | test_must_fail git prune garbage && |
| 78 | test_must_fail git prune --- && |
| 79 | test_must_fail git prune --no-such-option |
Michele Ballabio | 0c62705 | 2008-03-23 22:34:34 +0100 | [diff] [blame] | 80 | ' |
| 81 | |
| 82 | test_expect_success 'prune: prune unreachable heads' ' |
Michele Ballabio | 0c62705 | 2008-03-23 22:34:34 +0100 | [diff] [blame] | 83 | git config core.logAllRefUpdates false && |
Han-Wen Nienhuys | d491f5e | 2021-05-31 16:56:28 +0000 | [diff] [blame] | 84 | >file2 && |
Michele Ballabio | 0c62705 | 2008-03-23 22:34:34 +0100 | [diff] [blame] | 85 | git add file2 && |
| 86 | git commit -m temporary && |
| 87 | tmp_head=$(git rev-list -1 HEAD) && |
| 88 | git reset HEAD^ && |
Han-Wen Nienhuys | d491f5e | 2021-05-31 16:56:28 +0000 | [diff] [blame] | 89 | git reflog expire --all && |
Michele Ballabio | 0c62705 | 2008-03-23 22:34:34 +0100 | [diff] [blame] | 90 | git prune && |
| 91 | test_must_fail git reset $tmp_head -- |
Michele Ballabio | 0c62705 | 2008-03-23 22:34:34 +0100 | [diff] [blame] | 92 | ' |
| 93 | |
Max Kirillov | c40fdd0 | 2014-09-03 19:14:10 +0300 | [diff] [blame] | 94 | test_expect_success 'prune: do not prune detached HEAD with no reflog' ' |
Max Kirillov | c40fdd0 | 2014-09-03 19:14:10 +0300 | [diff] [blame] | 95 | git checkout --detach --quiet && |
| 96 | git commit --allow-empty -m "detached commit" && |
Han-Wen Nienhuys | d491f5e | 2021-05-31 16:56:28 +0000 | [diff] [blame] | 97 | git reflog expire --all && |
Max Kirillov | c40fdd0 | 2014-09-03 19:14:10 +0300 | [diff] [blame] | 98 | git prune -n >prune_actual && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 99 | test_must_be_empty prune_actual |
Max Kirillov | c40fdd0 | 2014-09-03 19:14:10 +0300 | [diff] [blame] | 100 | ' |
| 101 | |
| 102 | test_expect_success 'prune: prune former HEAD after checking out branch' ' |
Jeff King | cc80c95 | 2019-02-14 06:07:36 -0500 | [diff] [blame] | 103 | head_oid=$(git rev-parse HEAD) && |
Johannes Schindelin | 966b4be | 2020-11-18 23:44:29 +0000 | [diff] [blame] | 104 | git checkout --quiet main && |
Han-Wen Nienhuys | d491f5e | 2021-05-31 16:56:28 +0000 | [diff] [blame] | 105 | git reflog expire --all && |
Max Kirillov | c40fdd0 | 2014-09-03 19:14:10 +0300 | [diff] [blame] | 106 | git prune -v >prune_actual && |
Jeff King | cc80c95 | 2019-02-14 06:07:36 -0500 | [diff] [blame] | 107 | grep "$head_oid" prune_actual |
Max Kirillov | c40fdd0 | 2014-09-03 19:14:10 +0300 | [diff] [blame] | 108 | ' |
| 109 | |
Junio C Hamano | fe308f5 | 2008-03-24 23:20:51 -0700 | [diff] [blame] | 110 | test_expect_success 'prune: do not prune heads listed as an argument' ' |
Han-Wen Nienhuys | 1fa9cf6 | 2021-05-31 16:56:27 +0000 | [diff] [blame] | 111 | >file2 && |
Michele Ballabio | 0c62705 | 2008-03-23 22:34:34 +0100 | [diff] [blame] | 112 | git add file2 && |
| 113 | git commit -m temporary && |
| 114 | tmp_head=$(git rev-list -1 HEAD) && |
| 115 | git reset HEAD^ && |
| 116 | git prune -- $tmp_head && |
| 117 | git reset $tmp_head -- |
Michele Ballabio | 0c62705 | 2008-03-23 22:34:34 +0100 | [diff] [blame] | 118 | ' |
| 119 | |
Johannes Schindelin | 58e9d9d | 2009-02-14 23:10:10 +0100 | [diff] [blame] | 120 | test_expect_success 'gc --no-prune' ' |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 121 | add_blob && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 122 | test-tool chmtime =-$((5001*$day)) $BLOB_FILE && |
Johannes Schindelin | 58e9d9d | 2009-02-14 23:10:10 +0100 | [diff] [blame] | 123 | git config gc.pruneExpire 2.days.ago && |
| 124 | git gc --no-prune && |
Jeff King | 8ad1652 | 2014-10-10 02:11:14 -0400 | [diff] [blame] | 125 | verbose test 1 = $(git count-objects | sed "s/ .*//") && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 126 | test_path_is_file $BLOB_FILE |
Johannes Schindelin | 58e9d9d | 2009-02-14 23:10:10 +0100 | [diff] [blame] | 127 | ' |
| 128 | |
| 129 | test_expect_success 'gc respects gc.pruneExpire' ' |
Johannes Schindelin | 58e9d9d | 2009-02-14 23:10:10 +0100 | [diff] [blame] | 130 | git config gc.pruneExpire 5002.days.ago && |
| 131 | git gc && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 132 | test_path_is_file $BLOB_FILE && |
Johannes Schindelin | 58e9d9d | 2009-02-14 23:10:10 +0100 | [diff] [blame] | 133 | git config gc.pruneExpire 5000.days.ago && |
| 134 | git gc && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 135 | test_path_is_missing $BLOB_FILE |
Johannes Schindelin | 58e9d9d | 2009-02-14 23:10:10 +0100 | [diff] [blame] | 136 | ' |
| 137 | |
| 138 | test_expect_success 'gc --prune=<date>' ' |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 139 | add_blob && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 140 | test-tool chmtime =-$((5001*$day)) $BLOB_FILE && |
Johannes Schindelin | 58e9d9d | 2009-02-14 23:10:10 +0100 | [diff] [blame] | 141 | git gc --prune=5002.days.ago && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 142 | test_path_is_file $BLOB_FILE && |
Johannes Schindelin | 58e9d9d | 2009-02-14 23:10:10 +0100 | [diff] [blame] | 143 | git gc --prune=5000.days.ago && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 144 | test_path_is_missing $BLOB_FILE |
Johannes Schindelin | 58e9d9d | 2009-02-14 23:10:10 +0100 | [diff] [blame] | 145 | ' |
| 146 | |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 147 | test_expect_success 'gc --prune=never' ' |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 148 | add_blob && |
| 149 | git gc --prune=never && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 150 | test_path_is_file $BLOB_FILE && |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 151 | git gc --prune=now && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 152 | test_path_is_missing $BLOB_FILE |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 153 | ' |
| 154 | |
| 155 | test_expect_success 'gc respects gc.pruneExpire=never' ' |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 156 | git config gc.pruneExpire never && |
| 157 | add_blob && |
| 158 | git gc && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 159 | test_path_is_file $BLOB_FILE && |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 160 | git config gc.pruneExpire now && |
| 161 | git gc && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 162 | test_path_is_missing $BLOB_FILE |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 163 | ' |
| 164 | |
| 165 | test_expect_success 'prune --expire=never' ' |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 166 | add_blob && |
| 167 | git prune --expire=never && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 168 | test_path_is_file $BLOB_FILE && |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 169 | git prune && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 170 | test_path_is_missing $BLOB_FILE |
Adam Simpkins | cbf731e | 2010-02-26 19:50:02 -0800 | [diff] [blame] | 171 | ' |
| 172 | |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 173 | test_expect_success 'gc: prune old objects after local clone' ' |
| 174 | add_blob && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 175 | test-tool chmtime =-$((2*$week+1)) $BLOB_FILE && |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 176 | git clone --no-hardlinks . aclone && |
| 177 | ( |
| 178 | cd aclone && |
Jeff King | 8ad1652 | 2014-10-10 02:11:14 -0400 | [diff] [blame] | 179 | verbose test 1 = $(git count-objects | sed "s/ .*//") && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 180 | test_path_is_file $BLOB_FILE && |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 181 | git gc --prune && |
Jeff King | 8ad1652 | 2014-10-10 02:11:14 -0400 | [diff] [blame] | 182 | verbose test 0 = $(git count-objects | sed "s/ .*//") && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 183 | test_path_is_missing $BLOB_FILE |
Clemens Buchacher | 98df233 | 2009-09-13 12:49:45 +0200 | [diff] [blame] | 184 | ) |
| 185 | ' |
| 186 | |
Nguyễn Thái Ngọc Duy | 543c5ca | 2013-02-15 19:07:10 +0700 | [diff] [blame] | 187 | test_expect_success 'garbage report in count-objects -v' ' |
Jeff King | f813e9e | 2015-06-22 06:40:50 -0400 | [diff] [blame] | 188 | test_when_finished "rm -f .git/objects/pack/fake*" && |
Doug Kelly | e6d65c9 | 2015-11-03 21:05:07 -0600 | [diff] [blame] | 189 | test_when_finished "rm -f .git/objects/pack/foo*" && |
Han-Wen Nienhuys | 1fa9cf6 | 2021-05-31 16:56:27 +0000 | [diff] [blame] | 190 | >.git/objects/pack/foo && |
| 191 | >.git/objects/pack/foo.bar && |
| 192 | >.git/objects/pack/foo.keep && |
| 193 | >.git/objects/pack/foo.pack && |
| 194 | >.git/objects/pack/fake.bar && |
| 195 | >.git/objects/pack/fake.keep && |
| 196 | >.git/objects/pack/fake.pack && |
| 197 | >.git/objects/pack/fake.idx && |
| 198 | >.git/objects/pack/fake2.keep && |
| 199 | >.git/objects/pack/fake3.idx && |
Nguyễn Thái Ngọc Duy | 543c5ca | 2013-02-15 19:07:10 +0700 | [diff] [blame] | 200 | git count-objects -v 2>stderr && |
| 201 | grep "index file .git/objects/pack/fake.idx is too small" stderr && |
| 202 | grep "^warning:" stderr | sort >actual && |
| 203 | cat >expected <<\EOF && |
| 204 | warning: garbage found: .git/objects/pack/fake.bar |
| 205 | warning: garbage found: .git/objects/pack/foo |
| 206 | warning: garbage found: .git/objects/pack/foo.bar |
Justin Lebar | 235e8d5 | 2014-03-31 15:11:47 -0700 | [diff] [blame] | 207 | warning: no corresponding .idx or .pack: .git/objects/pack/fake2.keep |
Nguyễn Thái Ngọc Duy | 543c5ca | 2013-02-15 19:07:10 +0700 | [diff] [blame] | 208 | warning: no corresponding .idx: .git/objects/pack/foo.keep |
| 209 | warning: no corresponding .idx: .git/objects/pack/foo.pack |
| 210 | warning: no corresponding .pack: .git/objects/pack/fake3.idx |
| 211 | EOF |
| 212 | test_cmp expected actual |
| 213 | ' |
| 214 | |
Doug Kelly | 478f34d | 2015-11-03 21:05:08 -0600 | [diff] [blame] | 215 | test_expect_success 'clean pack garbage with gc' ' |
Doug Kelly | e6d65c9 | 2015-11-03 21:05:07 -0600 | [diff] [blame] | 216 | test_when_finished "rm -f .git/objects/pack/fake*" && |
| 217 | test_when_finished "rm -f .git/objects/pack/foo*" && |
Han-Wen Nienhuys | 1fa9cf6 | 2021-05-31 16:56:27 +0000 | [diff] [blame] | 218 | >.git/objects/pack/foo.keep && |
| 219 | >.git/objects/pack/foo.pack && |
| 220 | >.git/objects/pack/fake.idx && |
| 221 | >.git/objects/pack/fake2.keep && |
| 222 | >.git/objects/pack/fake2.idx && |
| 223 | >.git/objects/pack/fake3.keep && |
Doug Kelly | e6d65c9 | 2015-11-03 21:05:07 -0600 | [diff] [blame] | 224 | git gc && |
| 225 | git count-objects -v 2>stderr && |
| 226 | grep "^warning:" stderr | sort >actual && |
| 227 | cat >expected <<\EOF && |
| 228 | warning: no corresponding .idx or .pack: .git/objects/pack/fake3.keep |
| 229 | warning: no corresponding .idx: .git/objects/pack/foo.keep |
| 230 | warning: no corresponding .idx: .git/objects/pack/foo.pack |
| 231 | EOF |
| 232 | test_cmp expected actual |
| 233 | ' |
| 234 | |
Nguyễn Thái Ngọc Duy | eab3296 | 2013-12-05 20:02:54 +0700 | [diff] [blame] | 235 | test_expect_success 'prune .git/shallow' ' |
Jeff King | cc80c95 | 2019-02-14 06:07:36 -0500 | [diff] [blame] | 236 | oid=$(echo hi|git commit-tree HEAD^{tree}) && |
| 237 | echo $oid >.git/shallow && |
Nguyễn Thái Ngọc Duy | eab3296 | 2013-12-05 20:02:54 +0700 | [diff] [blame] | 238 | git prune --dry-run >out && |
Jeff King | cc80c95 | 2019-02-14 06:07:36 -0500 | [diff] [blame] | 239 | grep $oid .git/shallow && |
| 240 | grep $oid out && |
Nguyễn Thái Ngọc Duy | eab3296 | 2013-12-05 20:02:54 +0700 | [diff] [blame] | 241 | git prune && |
Jeff King | f1dd90b | 2014-10-10 02:07:00 -0400 | [diff] [blame] | 242 | test_path_is_missing .git/shallow |
Nguyễn Thái Ngọc Duy | eab3296 | 2013-12-05 20:02:54 +0700 | [diff] [blame] | 243 | ' |
| 244 | |
Jeff King | d55a30b | 2019-02-13 23:35:22 -0500 | [diff] [blame] | 245 | test_expect_success 'prune .git/shallow when there are no loose objects' ' |
Jeff King | cc80c95 | 2019-02-14 06:07:36 -0500 | [diff] [blame] | 246 | oid=$(echo hi|git commit-tree HEAD^{tree}) && |
| 247 | echo $oid >.git/shallow && |
| 248 | git update-ref refs/heads/shallow-tip $oid && |
Jeff King | d55a30b | 2019-02-13 23:35:22 -0500 | [diff] [blame] | 249 | git repack -ad && |
| 250 | # verify assumption that all loose objects are gone |
| 251 | git count-objects | grep ^0 && |
| 252 | git prune && |
Jeff King | cc80c95 | 2019-02-14 06:07:36 -0500 | [diff] [blame] | 253 | echo $oid >expect && |
Jeff King | d55a30b | 2019-02-13 23:35:22 -0500 | [diff] [blame] | 254 | test_cmp expect .git/shallow |
| 255 | ' |
| 256 | |
Jonathon Mah | b0a4264 | 2015-02-08 20:15:39 -0500 | [diff] [blame] | 257 | test_expect_success 'prune: handle alternate object database' ' |
| 258 | test_create_repo A && |
| 259 | git -C A commit --allow-empty -m "initial commit" && |
| 260 | git clone --shared A B && |
| 261 | git -C B commit --allow-empty -m "next commit" && |
| 262 | git -C B prune |
| 263 | ' |
| 264 | |
Nguyễn Thái Ngọc Duy | be489d0 | 2017-08-23 19:36:52 +0700 | [diff] [blame] | 265 | test_expect_success 'prune: handle index in multiple worktrees' ' |
| 266 | git worktree add second-worktree && |
| 267 | echo "new blob for second-worktree" >second-worktree/blob && |
| 268 | git -C second-worktree add blob && |
| 269 | git prune --expire=now && |
| 270 | git -C second-worktree show :blob >actual && |
| 271 | test_cmp second-worktree/blob actual |
| 272 | ' |
| 273 | |
Nguyễn Thái Ngọc Duy | d0c39a4 | 2017-08-23 19:36:59 +0700 | [diff] [blame] | 274 | test_expect_success 'prune: handle HEAD in multiple worktrees' ' |
| 275 | git worktree add --detach third-worktree && |
| 276 | echo "new blob for third-worktree" >third-worktree/blob && |
| 277 | git -C third-worktree add blob && |
| 278 | git -C third-worktree commit -m "third" && |
| 279 | rm .git/worktrees/third-worktree/index && |
| 280 | test_must_fail git -C third-worktree show :blob && |
| 281 | git prune --expire=now && |
| 282 | git -C third-worktree show HEAD:blob >actual && |
| 283 | test_cmp third-worktree/blob actual |
| 284 | ' |
| 285 | |
Nguyễn Thái Ngọc Duy | acd9544 | 2017-08-23 19:37:01 +0700 | [diff] [blame] | 286 | test_expect_success 'prune: handle HEAD reflog in multiple worktrees' ' |
| 287 | git config core.logAllRefUpdates true && |
| 288 | echo "lost blob for third-worktree" >expected && |
| 289 | ( |
| 290 | cd third-worktree && |
| 291 | cat ../expected >blob && |
| 292 | git add blob && |
| 293 | git commit -m "second commit in third" && |
Elijah Newren | f222bd3 | 2021-09-11 17:08:42 +0000 | [diff] [blame] | 294 | git clean -f && # Remove untracked left behind by deleting index |
Nguyễn Thái Ngọc Duy | acd9544 | 2017-08-23 19:37:01 +0700 | [diff] [blame] | 295 | git reset --hard HEAD^ |
| 296 | ) && |
| 297 | git prune --expire=now && |
Jeff King | cc80c95 | 2019-02-14 06:07:36 -0500 | [diff] [blame] | 298 | oid=`git hash-object expected` && |
| 299 | git -C third-worktree show "$oid" >actual && |
Nguyễn Thái Ngọc Duy | acd9544 | 2017-08-23 19:37:01 +0700 | [diff] [blame] | 300 | test_cmp expected actual |
| 301 | ' |
| 302 | |
Junio C Hamano | 8ab5aa4 | 2018-04-21 12:13:13 +0900 | [diff] [blame] | 303 | test_expect_success 'prune: handle expire option correctly' ' |
| 304 | test_must_fail git prune --expire 2>error && |
| 305 | test_i18ngrep "requires a value" error && |
| 306 | |
| 307 | test_must_fail git prune --expire=nyah 2>error && |
| 308 | test_i18ngrep "malformed expiration" error && |
| 309 | |
| 310 | git prune --no-expire |
| 311 | ' |
| 312 | |
Jeff King | fe6f2b0 | 2019-04-18 16:08:27 -0400 | [diff] [blame] | 313 | test_expect_success 'trivial prune with bitmaps enabled' ' |
| 314 | git repack -adb && |
| 315 | blob=$(echo bitmap-unreachable-blob | git hash-object -w --stdin) && |
| 316 | git prune --expire=now && |
| 317 | git cat-file -e HEAD && |
| 318 | test_must_fail git cat-file -e $blob |
| 319 | ' |
| 320 | |
Jeff King | 2ba582b | 2021-04-28 11:42:43 -0400 | [diff] [blame] | 321 | test_expect_success 'old reachable-from-recent retained with bitmaps' ' |
| 322 | git repack -adb && |
| 323 | to_drop=$(echo bitmap-from-recent-1 | git hash-object -w --stdin) && |
| 324 | test-tool chmtime -86400 .git/objects/$(test_oid_to_path $to_drop) && |
| 325 | to_save=$(echo bitmap-from-recent-2 | git hash-object -w --stdin) && |
| 326 | test-tool chmtime -86400 .git/objects/$(test_oid_to_path $to_save) && |
| 327 | tree=$(printf "100644 blob $to_save\tfile\n" | git mktree) && |
| 328 | test-tool chmtime -86400 .git/objects/$(test_oid_to_path $tree) && |
| 329 | commit=$(echo foo | git commit-tree $tree) && |
| 330 | git prune --expire=12.hours.ago && |
| 331 | git cat-file -e $commit && |
| 332 | git cat-file -e $tree && |
| 333 | git cat-file -e $to_save && |
| 334 | test_must_fail git cat-file -e $to_drop |
| 335 | ' |
| 336 | |
David Steven Tweed | 8464010 | 2008-02-07 02:55:14 +0000 | [diff] [blame] | 337 | test_done |