6
6
test_description=' prune'
7
7
. ./test-lib.sh
8
8
9
+ day=$(( 60 * 60 * 24 ))
10
+ week=$(( $day * 7 ))
11
+
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
+ }
19
+
9
20
test_expect_success setup '
10
21
11
22
: > file &&
@@ -31,11 +42,7 @@ test_expect_success 'prune stale packs' '
31
42
32
43
test_expect_success ' prune --expire' '
33
44
34
- before=$(git count-objects | sed "s/ .*//") &&
35
- BLOB=$(echo aleph | git hash-object -w --stdin) &&
36
- BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
37
- test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
38
- test -f $BLOB_FILE &&
45
+ add_blob &&
39
46
git prune --expire=1.hour.ago &&
40
47
test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
41
48
test -f $BLOB_FILE &&
@@ -48,16 +55,12 @@ test_expect_success 'prune --expire' '
48
55
49
56
test_expect_success ' gc: implicit prune --expire' '
50
57
51
- before=$(git count-objects | sed "s/ .*//") &&
52
- BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
53
- BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
54
- test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
55
- test -f $BLOB_FILE &&
56
- test-chmtime =-$((86400*14-30)) $BLOB_FILE &&
58
+ add_blob &&
59
+ test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
57
60
git gc &&
58
61
test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
59
62
test -f $BLOB_FILE &&
60
- test-chmtime =-$((86400*14 +1)) $BLOB_FILE &&
63
+ test-chmtime =-$((2*$week +1)) $BLOB_FILE &&
61
64
git gc &&
62
65
test $before = $(git count-objects | sed "s/ .*//") &&
63
66
! test -f $BLOB_FILE
@@ -114,12 +117,8 @@ test_expect_success 'prune: do not prune heads listed as an argument' '
114
117
115
118
test_expect_success ' gc --no-prune' '
116
119
117
- before=$(git count-objects | sed "s/ .*//") &&
118
- BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
119
- BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
120
- test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
121
- test -f $BLOB_FILE &&
122
- test-chmtime =-$((86400*5001)) $BLOB_FILE &&
120
+ add_blob &&
121
+ test-chmtime =-$((5001*$day)) $BLOB_FILE &&
123
122
git config gc.pruneExpire 2.days.ago &&
124
123
git gc --no-prune &&
125
124
test 1 = $(git count-objects | sed "s/ .*//") &&
@@ -140,14 +139,27 @@ test_expect_success 'gc respects gc.pruneExpire' '
140
139
141
140
test_expect_success ' gc --prune=<date>' '
142
141
143
- BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
144
- BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
145
- test-chmtime =-$((86400*5001)) $BLOB_FILE &&
142
+ add_blob &&
143
+ test-chmtime =-$((5001*$day)) $BLOB_FILE &&
146
144
git gc --prune=5002.days.ago &&
147
145
test -f $BLOB_FILE &&
148
146
git gc --prune=5000.days.ago &&
149
147
test ! -f $BLOB_FILE
150
148
151
149
'
152
150
151
+ test_expect_success ' gc: prune old objects after local clone' '
152
+ add_blob &&
153
+ test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
154
+ git clone --no-hardlinks . aclone &&
155
+ (
156
+ cd aclone &&
157
+ test 1 = $(git count-objects | sed "s/ .*//") &&
158
+ test -f $BLOB_FILE &&
159
+ git gc --prune &&
160
+ test 0 = $(git count-objects | sed "s/ .*//") &&
161
+ ! test -f $BLOB_FILE
162
+ )
163
+ '
164
+
153
165
test_done
0 commit comments