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