i18n: rev-parse: mark parseopt strings for translation
[git/jnareb-git.git] / t / t5304-prune.sh
blobd645328609c9ec63782a0b9f80c31a73ef745802
1 #!/bin/sh
3 # Copyright (c) 2008 Johannes E. Schindelin
6 test_description='prune'
7 . ./test-lib.sh
9 day=$((60*60*24))
10 week=$(($day*7))
12 add_blob() {
13 before=$(git count-objects | sed "s/ .*//") &&
14 BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
15 BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
16 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
17 test -f $BLOB_FILE &&
18 test-chmtime =+0 $BLOB_FILE
21 test_expect_success setup '
23 : > file &&
24 git add file &&
25 test_tick &&
26 git commit -m initial &&
27 git gc
31 test_expect_success 'prune stale packs' '
33 orig_pack=$(echo .git/objects/pack/*.pack) &&
34 : > .git/objects/tmp_1.pack &&
35 : > .git/objects/tmp_2.pack &&
36 test-chmtime =-86501 .git/objects/tmp_1.pack &&
37 git prune --expire 1.day &&
38 test -f $orig_pack &&
39 test -f .git/objects/tmp_2.pack &&
40 ! test -f .git/objects/tmp_1.pack
44 test_expect_success 'prune --expire' '
46 add_blob &&
47 git prune --expire=1.hour.ago &&
48 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
49 test -f $BLOB_FILE &&
50 test-chmtime =-86500 $BLOB_FILE &&
51 git prune --expire 1.day &&
52 test $before = $(git count-objects | sed "s/ .*//") &&
53 ! test -f $BLOB_FILE
57 test_expect_success 'gc: implicit prune --expire' '
59 add_blob &&
60 test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
61 git gc &&
62 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
63 test -f $BLOB_FILE &&
64 test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
65 git gc &&
66 test $before = $(git count-objects | sed "s/ .*//") &&
67 ! test -f $BLOB_FILE
71 test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '
73 git config gc.pruneExpire invalid &&
74 test_must_fail git gc
78 test_expect_success 'gc: start with ok gc.pruneExpire' '
80 git config gc.pruneExpire 2.days.ago &&
81 git gc
85 test_expect_success 'prune: prune nonsense parameters' '
87 test_must_fail git prune garbage &&
88 test_must_fail git prune --- &&
89 test_must_fail git prune --no-such-option
93 test_expect_success 'prune: prune unreachable heads' '
95 git config core.logAllRefUpdates false &&
96 mv .git/logs .git/logs.old &&
97 : > file2 &&
98 git add file2 &&
99 git commit -m temporary &&
100 tmp_head=$(git rev-list -1 HEAD) &&
101 git reset HEAD^ &&
102 git prune &&
103 test_must_fail git reset $tmp_head --
107 test_expect_success 'prune: do not prune heads listed as an argument' '
109 : > file2 &&
110 git add file2 &&
111 git commit -m temporary &&
112 tmp_head=$(git rev-list -1 HEAD) &&
113 git reset HEAD^ &&
114 git prune -- $tmp_head &&
115 git reset $tmp_head --
119 test_expect_success 'gc --no-prune' '
121 add_blob &&
122 test-chmtime =-$((5001*$day)) $BLOB_FILE &&
123 git config gc.pruneExpire 2.days.ago &&
124 git gc --no-prune &&
125 test 1 = $(git count-objects | sed "s/ .*//") &&
126 test -f $BLOB_FILE
130 test_expect_success 'gc respects gc.pruneExpire' '
132 git config gc.pruneExpire 5002.days.ago &&
133 git gc &&
134 test -f $BLOB_FILE &&
135 git config gc.pruneExpire 5000.days.ago &&
136 git gc &&
137 test ! -f $BLOB_FILE
141 test_expect_success 'gc --prune=<date>' '
143 add_blob &&
144 test-chmtime =-$((5001*$day)) $BLOB_FILE &&
145 git gc --prune=5002.days.ago &&
146 test -f $BLOB_FILE &&
147 git gc --prune=5000.days.ago &&
148 test ! -f $BLOB_FILE
152 test_expect_success 'gc --prune=never' '
154 add_blob &&
155 git gc --prune=never &&
156 test -f $BLOB_FILE &&
157 git gc --prune=now &&
158 test ! -f $BLOB_FILE
162 test_expect_success 'gc respects gc.pruneExpire=never' '
164 git config gc.pruneExpire never &&
165 add_blob &&
166 git gc &&
167 test -f $BLOB_FILE &&
168 git config gc.pruneExpire now &&
169 git gc &&
170 test ! -f $BLOB_FILE
174 test_expect_success 'prune --expire=never' '
176 add_blob &&
177 git prune --expire=never &&
178 test -f $BLOB_FILE &&
179 git prune &&
180 test ! -f $BLOB_FILE
184 test_expect_success 'gc: prune old objects after local clone' '
185 add_blob &&
186 test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
187 git clone --no-hardlinks . aclone &&
189 cd aclone &&
190 test 1 = $(git count-objects | sed "s/ .*//") &&
191 test -f $BLOB_FILE &&
192 git gc --prune &&
193 test 0 = $(git count-objects | sed "s/ .*//") &&
194 ! test -f $BLOB_FILE
198 test_done