Skip to content

Commit 3ddaad0

Browse files
derrickstoleegitster
authored andcommitted
maintenance: add --quiet option
Maintenance activities are commonly used as steps in larger scripts. Providing a '--quiet' option allows those scripts to be less noisy when run on a terminal window. Turn this mode on by default when stderr is not a terminal. Pipe the option to the 'git gc' child process. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2057d75 commit 3ddaad0

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

Documentation/git-maintenance.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ OPTIONS
5252
in the `gc.auto` config setting, or when the number of pack-files
5353
exceeds the `gc.autoPackLimit` config setting.
5454

55+
--quiet::
56+
Do not report progress or other information over `stderr`.
57+
5558
GIT
5659
---
5760
Part of the linkgit:git[1] suite

builtin/gc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,13 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
701701
}
702702

703703
static const char * const builtin_maintenance_run_usage[] = {
704-
N_("git maintenance run [--auto]"),
704+
N_("git maintenance run [--auto] [--[no-]quiet]"),
705705
NULL
706706
};
707707

708708
struct maintenance_run_opts {
709709
int auto_flag;
710+
int quiet;
710711
};
711712

712713
static int maintenance_task_gc(struct maintenance_run_opts *opts)
@@ -718,6 +719,10 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
718719

719720
if (opts->auto_flag)
720721
strvec_push(&child.args, "--auto");
722+
if (opts->quiet)
723+
strvec_push(&child.args, "--quiet");
724+
else
725+
strvec_push(&child.args, "--no-quiet");
721726

722727
close_object_store(the_repository->objects);
723728
return run_command(&child);
@@ -729,10 +734,14 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
729734
struct option builtin_maintenance_run_options[] = {
730735
OPT_BOOL(0, "auto", &opts.auto_flag,
731736
N_("run tasks based on the state of the repository")),
737+
OPT_BOOL(0, "quiet", &opts.quiet,
738+
N_("do not report progress or other information over stderr")),
732739
OPT_END()
733740
};
734741
memset(&opts, 0, sizeof(opts));
735742

743+
opts.quiet = !isatty(2);
744+
736745
argc = parse_options(argc, argv, prefix,
737746
builtin_maintenance_run_options,
738747
builtin_maintenance_run_usage,

t/t7900-maintenance.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ test_expect_success 'help text' '
1313
test_i18ngrep "usage: git maintenance" err
1414
'
1515

16-
test_expect_success 'run [--auto]' '
17-
GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" git maintenance run &&
18-
GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" git maintenance run --auto &&
19-
test_subcommand git gc <run-no-auto.txt &&
20-
test_subcommand git gc --auto <run-auto.txt
16+
test_expect_success 'run [--auto|--quiet]' '
17+
GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \
18+
git maintenance run 2>/dev/null &&
19+
GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \
20+
git maintenance run --auto 2>/dev/null &&
21+
GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
22+
git maintenance run --no-quiet 2>/dev/null &&
23+
test_subcommand git gc --quiet <run-no-auto.txt &&
24+
test_subcommand git gc --auto --quiet <run-auto.txt &&
25+
test_subcommand git gc --no-quiet <run-no-quiet.txt
2126
'
2227

2328
test_done

0 commit comments

Comments
 (0)