maintenance: core.commitGraph=false prevents writes
[git] / t / t7900-maintenance.sh
1 #!/bin/sh
2
3 test_description='git maintenance builtin'
4
5 . ./test-lib.sh
6
7 GIT_TEST_COMMIT_GRAPH=0
8
9 test_expect_success 'help text' '
10         test_expect_code 129 git maintenance -h 2>err &&
11         test_i18ngrep "usage: git maintenance run" err &&
12         test_expect_code 128 git maintenance barf 2>err &&
13         test_i18ngrep "invalid subcommand: barf" err &&
14         test_expect_code 129 git maintenance 2>err &&
15         test_i18ngrep "usage: git maintenance" err
16 '
17
18 test_expect_success 'run [--auto|--quiet]' '
19         GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \
20                 git maintenance run 2>/dev/null &&
21         GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \
22                 git maintenance run --auto 2>/dev/null &&
23         GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
24                 git maintenance run --no-quiet 2>/dev/null &&
25         test_subcommand git gc --quiet <run-no-auto.txt &&
26         test_subcommand ! git gc --auto --quiet <run-auto.txt &&
27         test_subcommand git gc --no-quiet <run-no-quiet.txt
28 '
29
30 test_expect_success 'maintenance.<task>.enabled' '
31         git config maintenance.gc.enabled false &&
32         git config maintenance.commit-graph.enabled true &&
33         GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err &&
34         test_subcommand ! git gc --quiet <run-config.txt &&
35         test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt
36 '
37
38 test_expect_success 'run --task=<task>' '
39         GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
40                 git maintenance run --task=commit-graph 2>/dev/null &&
41         GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \
42                 git maintenance run --task=gc 2>/dev/null &&
43         GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
44                 git maintenance run --task=commit-graph 2>/dev/null &&
45         GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
46                 git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
47         test_subcommand ! git gc --quiet <run-commit-graph.txt &&
48         test_subcommand git gc --quiet <run-gc.txt &&
49         test_subcommand git gc --quiet <run-both.txt &&
50         test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt &&
51         test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt &&
52         test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
53 '
54
55 test_expect_success 'core.commitGraph=false prevents write process' '
56         GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \
57                 git -c core.commitGraph=false maintenance run \
58                 --task=commit-graph 2>/dev/null &&
59         test_subcommand ! git commit-graph write --split --reachable --no-progress \
60                 <no-commit-graph.txt
61 '
62
63 test_expect_success 'commit-graph auto condition' '
64         COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
65
66         GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \
67                 git -c maintenance.commit-graph.auto=1 $COMMAND &&
68         GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
69                 git -c maintenance.commit-graph.auto="-1" $COMMAND &&
70
71         test_commit first &&
72
73         GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
74                 git -c maintenance.commit-graph.auto=0 $COMMAND &&
75         GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
76                 git -c maintenance.commit-graph.auto=1 $COMMAND &&
77
78         git commit --allow-empty -m "second" &&
79         git commit --allow-empty -m "third" &&
80
81         GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
82                 git -c maintenance.commit-graph.auto=2 $COMMAND &&
83
84         COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" &&
85         test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt &&
86         test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt &&
87         test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt &&
88         test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt &&
89         test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
90 '
91
92 test_expect_success 'run --task=bogus' '
93         test_must_fail git maintenance run --task=bogus 2>err &&
94         test_i18ngrep "is not a valid task" err
95 '
96
97 test_expect_success 'run --task duplicate' '
98         test_must_fail git maintenance run --task=gc --task=gc 2>err &&
99         test_i18ngrep "cannot be selected multiple times" err
100 '
101
102 test_done