worktree: add --quiet option

Add the '--quiet' option to git worktree, as for the other git commands. 'add' is the only command affected by it since all other commands, except 'list', are currently silent by default. [jc: appiled trivial fix-up to keep the tests from touching outside the scratch area] Helped-by: Martin Ågren <martin.agren@gmail.com> Helped-by: Duy Nguyen <pclouds@gmail.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elia Pinto committed Aug 15, 2018 at 20:56 UTC 371979c21745a8be34a556e663d71e3a984ff4ce
3 files changed +22 -3
Documentation/git-worktree.txt
+4
@@ -173,6 +173,10 @@ This can also be set up as the default behaviour by using the
173 This format will remain stable across Git versions and regardless of user
174 configuration. See below for details.
175
176 +-q::
177 +--quiet::
178 + With 'add', suppress feedback messages.
179 +
180 -v::
181 --verbose::
182 With `prune`, report all removals.
builtin/worktree.c
+13 -3
@@ -27,6 +27,7 @@ static const char * const worktree_usage[] = {
27 struct add_opts {
28 int force;
29 int detach;
30 + int quiet;
31 int checkout;
32 int keep_locked;
33 };
@@ -303,9 +304,13 @@ static int add_worktree(const char *path, const char *refname,
304 if (!is_branch)
305 argv_array_pushl(&cp.args, "update-ref", "HEAD",
306 oid_to_hex(&commit->object.oid), NULL);
306 - else
307 + else {
308 argv_array_pushl(&cp.args, "symbolic-ref", "HEAD",
309 symref.buf, NULL);
310 + if (opts->quiet)
311 + argv_array_push(&cp.args, "--quiet");
312 + }
313 +
314 cp.env = child_env.argv;
315 ret = run_command(&cp);
316 if (ret)
@@ -315,6 +320,8 @@ static int add_worktree(const char *path, const char *refname,
320 cp.argv = NULL;
321 argv_array_clear(&cp.args);
322 argv_array_pushl(&cp.args, "reset", "--hard", NULL);
323 + if (opts->quiet)
324 + argv_array_push(&cp.args, "--quiet");
325 cp.env = child_env.argv;
326 ret = run_command(&cp);
327 if (ret)
@@ -437,6 +444,7 @@ static int add(int ac, const char **av, const char *prefix)
444 OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named commit")),
445 OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
446 OPT_BOOL(0, "lock", &opts.keep_locked, N_("keep the new working tree locked")),
447 + OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),
448 OPT_PASSTHRU(0, "track", &opt_track, NULL,
449 N_("set up tracking mode (see git-branch(1))"),
450 PARSE_OPT_NOARG | PARSE_OPT_OPTARG),
@@ -491,8 +499,8 @@ static int add(int ac, const char **av, const char *prefix)
499 }
500 }
501 }
494 -
495 - print_preparing_worktree_line(opts.detach, branch, new_branch, !!new_branch_force);
502 + if (!opts.quiet)
503 + print_preparing_worktree_line(opts.detach, branch, new_branch, !!new_branch_force);
504
505 if (new_branch) {
506 struct child_process cp = CHILD_PROCESS_INIT;
@@ -500,6 +508,8 @@ static int add(int ac, const char **av, const char *prefix)
508 argv_array_push(&cp.args, "branch");
509 if (new_branch_force)
510 argv_array_push(&cp.args, "--force");
511 + if (opts.quiet)
512 + argv_array_push(&cp.args, "--quiet");
513 argv_array_push(&cp.args, new_branch);
514 argv_array_push(&cp.args, branch);
515 if (opt_track)
t/t2025-worktree-add.sh
+5
@@ -252,6 +252,11 @@ test_expect_success 'add -B' '
252 test_cmp_rev master^ poodle
253 '
254
255 +test_expect_success 'add --quiet' '
256 + git worktree add --quiet another-worktree master 2>actual &&
257 + test_must_be_empty actual
258 +'
259 +
260 test_expect_success 'local clone from linked checkout' '
261 git clone --local here here-clone &&
262 ( cd here-clone && git fsck )