]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6500-gc.sh
t1407: make hash size independent
[thirdparty/git.git] / t / t6500-gc.sh
CommitLineData
0c8151b6
NTND
1#!/bin/sh
2
3test_description='basic git gc tests
4'
5
6. ./test-lib.sh
7
9806f5a7
NTND
8test_expect_success 'setup' '
9 # do not let the amount of physical memory affects gc
10 # behavior, make sure we always pack everything to one pack by
11 # default
12 git config gc.bigPackThreshold 2g
13'
14
0c8151b6
NTND
15test_expect_success 'gc empty repository' '
16 git gc
17'
18
4c5baf02
JN
19test_expect_success 'gc does not leave behind pid file' '
20 git gc &&
21 test_path_is_missing .git/gc.pid
22'
23
0c8151b6
NTND
24test_expect_success 'gc --gobbledegook' '
25 test_expect_code 129 git gc --nonsense 2>err &&
9a001381 26 test_i18ngrep "[Uu]sage: git gc" err
0c8151b6
NTND
27'
28
29test_expect_success 'gc -h with invalid configuration' '
30 mkdir broken &&
31 (
32 cd broken &&
33 git init &&
34 echo "[gc] pruneexpire = CORRUPT" >>.git/config &&
35 test_expect_code 129 git gc -h >usage 2>&1
36 ) &&
9a001381 37 test_i18ngrep "[Uu]sage" broken/usage
0c8151b6
NTND
38'
39
14886b40 40test_expect_success 'gc is not aborted due to a stale symref' '
8c845cde
JS
41 git init remote &&
42 (
43 cd remote &&
44 test_commit initial &&
45 git clone . ../client &&
46 git branch -m develop &&
47 cd ../client &&
48 git fetch --prune &&
49 git gc
50 )
51'
52
ae4e89e5
NTND
53test_expect_success 'gc --keep-largest-pack' '
54 test_create_repo keep-pack &&
55 (
56 cd keep-pack &&
57 test_commit one &&
58 test_commit two &&
59 test_commit three &&
60 git gc &&
61 ( cd .git/objects/pack && ls *.pack ) >pack-list &&
62 test_line_count = 1 pack-list &&
63 BASE_PACK=.git/objects/pack/pack-*.pack &&
64 test_commit four &&
65 git repack -d &&
66 test_commit five &&
67 git repack -d &&
68 ( cd .git/objects/pack && ls *.pack ) >pack-list &&
69 test_line_count = 3 pack-list &&
70 git gc --keep-largest-pack &&
71 ( cd .git/objects/pack && ls *.pack ) >pack-list &&
72 test_line_count = 2 pack-list &&
73 test_path_is_file $BASE_PACK &&
74 git fsck
75 )
76'
77
bdf56de8
DT
78test_expect_success 'auto gc with too many loose objects does not attempt to create bitmaps' '
79 test_config gc.auto 3 &&
80 test_config gc.autodetach false &&
81 test_config pack.writebitmaps true &&
82 # We need to create two object whose sha1s start with 17
83 # since this is what git gc counts. As it happens, these
84 # two blobs will do so.
85 test_commit 263 &&
86 test_commit 410 &&
87 # Our first gc will create a pack; our second will create a second pack
88 git gc --auto &&
89 ls .git/objects/pack | sort >existing_packs &&
90 test_commit 523 &&
91 test_commit 790 &&
92
93 git gc --auto 2>err &&
94 test_i18ngrep ! "^warning:" err &&
95 ls .git/objects/pack/ | sort >post_packs &&
96 comm -1 -3 existing_packs post_packs >new &&
97 comm -2 -3 existing_packs post_packs >del &&
98 test_line_count = 0 del && # No packs are deleted
99 test_line_count = 2 new # There is one new pack and its .idx
100'
101
ef09036c
SG
102run_and_wait_for_auto_gc () {
103 # We read stdout from gc for the side effect of waiting until the
104 # background gc process exits, closing its fd 9. Furthermore, the
105 # variable assignment from a command substitution preserves the
106 # exit status of the main gc process.
107 # Note: this fd trickery doesn't work on Windows, but there is no
108 # need to, because on Win the auto gc always runs in the foreground.
109 doesnt_matter=$(git gc --auto 9>&1)
110}
111
a831c06a
DT
112test_expect_success 'background auto gc does not run if gc.log is present and recent but does if it is old' '
113 test_commit foo &&
114 test_commit bar &&
115 git repack &&
116 test_config gc.autopacklimit 1 &&
117 test_config gc.autodetach true &&
118 echo fleem >.git/gc.log &&
119 test_must_fail git gc --auto 2>err &&
120 test_i18ngrep "^error:" err &&
121 test_config gc.logexpiry 5.days &&
0e496492 122 test-tool chmtime =-345600 .git/gc.log &&
a831c06a
DT
123 test_must_fail git gc --auto &&
124 test_config gc.logexpiry 2.days &&
ef09036c
SG
125 run_and_wait_for_auto_gc &&
126 ls .git/objects/pack/pack-*.pack >packs &&
127 test_line_count = 1 packs
a831c06a 128'
bdf56de8 129
c45af94d
JK
130test_expect_success 'background auto gc respects lock for all operations' '
131 # make sure we run a background auto-gc
132 test_commit make-pack &&
133 git repack &&
134 test_config gc.autopacklimit 1 &&
135 test_config gc.autodetach true &&
136
137 # create a ref whose loose presence we can use to detect a pack-refs run
138 git update-ref refs/heads/should-be-loose HEAD &&
139 test_path_is_file .git/refs/heads/should-be-loose &&
140
141 # now fake a concurrent gc that holds the lock; we can use our
142 # shell pid so that it looks valid.
143 hostname=$(hostname || echo unknown) &&
144 printf "$$ %s" "$hostname" >.git/gc.pid &&
145
146 # our gc should exit zero without doing anything
147 run_and_wait_for_auto_gc &&
148 test_path_is_file .git/refs/heads/should-be-loose
149'
150
ef09036c
SG
151# DO NOT leave a detached auto gc process running near the end of the
152# test script: it can run long enough in the background to racily
153# interfere with the cleanup in 'test_done'.
154
0c8151b6 155test_done