]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6500-gc.sh
l10n: fr v2.23.0 round 2
[thirdparty/git.git] / t / t6500-gc.sh
1 #!/bin/sh
2
3 test_description='basic git gc tests
4 '
5
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-terminal.sh
8
9 test_expect_success 'setup' '
10 # do not let the amount of physical memory affects gc
11 # behavior, make sure we always pack everything to one pack by
12 # default
13 git config gc.bigPackThreshold 2g
14 '
15
16 test_expect_success 'gc empty repository' '
17 git gc
18 '
19
20 test_expect_success 'gc does not leave behind pid file' '
21 git gc &&
22 test_path_is_missing .git/gc.pid
23 '
24
25 test_expect_success 'gc --gobbledegook' '
26 test_expect_code 129 git gc --nonsense 2>err &&
27 test_i18ngrep "[Uu]sage: git gc" err
28 '
29
30 test_expect_success 'gc -h with invalid configuration' '
31 mkdir broken &&
32 (
33 cd broken &&
34 git init &&
35 echo "[gc] pruneexpire = CORRUPT" >>.git/config &&
36 test_expect_code 129 git gc -h >usage 2>&1
37 ) &&
38 test_i18ngrep "[Uu]sage" broken/usage
39 '
40
41 test_expect_success 'gc is not aborted due to a stale symref' '
42 git init remote &&
43 (
44 cd remote &&
45 test_commit initial &&
46 git clone . ../client &&
47 git branch -m develop &&
48 cd ../client &&
49 git fetch --prune &&
50 git gc
51 )
52 '
53
54 test_expect_success 'gc --keep-largest-pack' '
55 test_create_repo keep-pack &&
56 (
57 cd keep-pack &&
58 test_commit one &&
59 test_commit two &&
60 test_commit three &&
61 git gc &&
62 ( cd .git/objects/pack && ls *.pack ) >pack-list &&
63 test_line_count = 1 pack-list &&
64 BASE_PACK=.git/objects/pack/pack-*.pack &&
65 test_commit four &&
66 git repack -d &&
67 test_commit five &&
68 git repack -d &&
69 ( cd .git/objects/pack && ls *.pack ) >pack-list &&
70 test_line_count = 3 pack-list &&
71 git gc --keep-largest-pack &&
72 ( cd .git/objects/pack && ls *.pack ) >pack-list &&
73 test_line_count = 2 pack-list &&
74 awk "/^P /{print \$2}" <.git/objects/info/packs >pack-info &&
75 test_line_count = 2 pack-info &&
76 test_path_is_file $BASE_PACK &&
77 git fsck
78 )
79 '
80
81 test_expect_success 'auto gc with too many loose objects does not attempt to create bitmaps' '
82 test_config gc.auto 3 &&
83 test_config gc.autodetach false &&
84 test_config pack.writebitmaps true &&
85 # We need to create two object whose sha1s start with 17
86 # since this is what git gc counts. As it happens, these
87 # two blobs will do so.
88 test_commit 263 &&
89 test_commit 410 &&
90 # Our first gc will create a pack; our second will create a second pack
91 git gc --auto &&
92 ls .git/objects/pack | sort >existing_packs &&
93 test_commit 523 &&
94 test_commit 790 &&
95
96 git gc --auto 2>err &&
97 test_i18ngrep ! "^warning:" err &&
98 ls .git/objects/pack/ | sort >post_packs &&
99 comm -1 -3 existing_packs post_packs >new &&
100 comm -2 -3 existing_packs post_packs >del &&
101 test_line_count = 0 del && # No packs are deleted
102 test_line_count = 2 new # There is one new pack and its .idx
103 '
104
105 test_expect_success 'gc --no-quiet' '
106 git -c gc.writeCommitGraph=true gc --no-quiet >stdout 2>stderr &&
107 test_must_be_empty stdout &&
108 test_line_count = 1 stderr &&
109 test_i18ngrep "Computing commit graph generation numbers" stderr
110 '
111
112 test_expect_success TTY 'with TTY: gc --no-quiet' '
113 test_terminal git -c gc.writeCommitGraph=true gc --no-quiet >stdout 2>stderr &&
114 test_must_be_empty stdout &&
115 test_i18ngrep "Enumerating objects" stderr &&
116 test_i18ngrep "Computing commit graph generation numbers" stderr
117 '
118
119 test_expect_success 'gc --quiet' '
120 git -c gc.writeCommitGraph=true gc --quiet >stdout 2>stderr &&
121 test_must_be_empty stdout &&
122 test_must_be_empty stderr
123 '
124
125 test_expect_success 'gc.reflogExpire{Unreachable,}=never skips "expire" via "gc"' '
126 test_config gc.reflogExpire never &&
127 test_config gc.reflogExpireUnreachable never &&
128
129 GIT_TRACE=$(pwd)/trace.out git gc &&
130
131 # Check that git-pack-refs is run as a sanity check (done via
132 # gc_before_repack()) but that git-expire is not.
133 grep -E "^trace: (built-in|exec|run_command): git pack-refs --" trace.out &&
134 ! grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out
135 '
136
137 test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "expire" via "gc"' '
138 >trace.out &&
139 test_config gc.reflogExpire never &&
140 GIT_TRACE=$(pwd)/trace.out git gc &&
141 grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out
142 '
143
144 run_and_wait_for_auto_gc () {
145 # We read stdout from gc for the side effect of waiting until the
146 # background gc process exits, closing its fd 9. Furthermore, the
147 # variable assignment from a command substitution preserves the
148 # exit status of the main gc process.
149 # Note: this fd trickery doesn't work on Windows, but there is no
150 # need to, because on Win the auto gc always runs in the foreground.
151 doesnt_matter=$(git gc --auto 9>&1)
152 }
153
154 test_expect_success 'background auto gc does not run if gc.log is present and recent but does if it is old' '
155 test_commit foo &&
156 test_commit bar &&
157 git repack &&
158 test_config gc.autopacklimit 1 &&
159 test_config gc.autodetach true &&
160 echo fleem >.git/gc.log &&
161 git gc --auto 2>err &&
162 test_i18ngrep "^warning:" err &&
163 test_config gc.logexpiry 5.days &&
164 test-tool chmtime =-345600 .git/gc.log &&
165 git gc --auto &&
166 test_config gc.logexpiry 2.days &&
167 run_and_wait_for_auto_gc &&
168 ls .git/objects/pack/pack-*.pack >packs &&
169 test_line_count = 1 packs
170 '
171
172 test_expect_success 'background auto gc respects lock for all operations' '
173 # make sure we run a background auto-gc
174 test_commit make-pack &&
175 git repack &&
176 test_config gc.autopacklimit 1 &&
177 test_config gc.autodetach true &&
178
179 # create a ref whose loose presence we can use to detect a pack-refs run
180 git update-ref refs/heads/should-be-loose HEAD &&
181 test_path_is_file .git/refs/heads/should-be-loose &&
182
183 # now fake a concurrent gc that holds the lock; we can use our
184 # shell pid so that it looks valid.
185 hostname=$(hostname || echo unknown) &&
186 shell_pid=$$ &&
187 if test_have_prereq MINGW && test -f /proc/$shell_pid/winpid
188 then
189 # In Git for Windows, Bash (actually, the MSYS2 runtime) has a
190 # different idea of PIDs than git.exe (actually Windows). Use
191 # the Windows PID in this case.
192 shell_pid=$(cat /proc/$shell_pid/winpid)
193 fi &&
194 printf "%d %s" "$shell_pid" "$hostname" >.git/gc.pid &&
195
196 # our gc should exit zero without doing anything
197 run_and_wait_for_auto_gc &&
198 test_path_is_file .git/refs/heads/should-be-loose
199 '
200
201 # DO NOT leave a detached auto gc process running near the end of the
202 # test script: it can run long enough in the background to racily
203 # interfere with the cleanup in 'test_done'.
204
205 test_done