Skip to content

Commit a988ce9

Browse files
committed
Merge branch 'ep/worktree-quiet-option'
"git worktree" command learned "--quiet" option to make it less verbose. * ep/worktree-quiet-option: worktree: add --quiet option
2 parents d89db6f + 371979c commit a988ce9

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Documentation/git-worktree.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ This can also be set up as the default behaviour by using the
173173
This format will remain stable across Git versions and regardless of user
174174
configuration. See below for details.
175175

176+
-q::
177+
--quiet::
178+
With 'add', suppress feedback messages.
179+
176180
-v::
177181
--verbose::
178182
With `prune`, report all removals.

builtin/worktree.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static const char * const worktree_usage[] = {
2727
struct add_opts {
2828
int force;
2929
int detach;
30+
int quiet;
3031
int checkout;
3132
int keep_locked;
3233
};
@@ -303,9 +304,13 @@ static int add_worktree(const char *path, const char *refname,
303304
if (!is_branch)
304305
argv_array_pushl(&cp.args, "update-ref", "HEAD",
305306
oid_to_hex(&commit->object.oid), NULL);
306-
else
307+
else {
307308
argv_array_pushl(&cp.args, "symbolic-ref", "HEAD",
308309
symref.buf, NULL);
310+
if (opts->quiet)
311+
argv_array_push(&cp.args, "--quiet");
312+
}
313+
309314
cp.env = child_env.argv;
310315
ret = run_command(&cp);
311316
if (ret)
@@ -315,6 +320,8 @@ static int add_worktree(const char *path, const char *refname,
315320
cp.argv = NULL;
316321
argv_array_clear(&cp.args);
317322
argv_array_pushl(&cp.args, "reset", "--hard", NULL);
323+
if (opts->quiet)
324+
argv_array_push(&cp.args, "--quiet");
318325
cp.env = child_env.argv;
319326
ret = run_command(&cp);
320327
if (ret)
@@ -437,6 +444,7 @@ static int add(int ac, const char **av, const char *prefix)
437444
OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named commit")),
438445
OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
439446
OPT_BOOL(0, "lock", &opts.keep_locked, N_("keep the new working tree locked")),
447+
OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),
440448
OPT_PASSTHRU(0, "track", &opt_track, NULL,
441449
N_("set up tracking mode (see git-branch(1))"),
442450
PARSE_OPT_NOARG | PARSE_OPT_OPTARG),
@@ -491,15 +499,17 @@ static int add(int ac, const char **av, const char *prefix)
491499
}
492500
}
493501
}
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);
496504

497505
if (new_branch) {
498506
struct child_process cp = CHILD_PROCESS_INIT;
499507
cp.git_cmd = 1;
500508
argv_array_push(&cp.args, "branch");
501509
if (new_branch_force)
502510
argv_array_push(&cp.args, "--force");
511+
if (opts.quiet)
512+
argv_array_push(&cp.args, "--quiet");
503513
argv_array_push(&cp.args, new_branch);
504514
argv_array_push(&cp.args, branch);
505515
if (opt_track)

t/t2025-worktree-add.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ test_expect_success 'add -B' '
252252
test_cmp_rev master^ poodle
253253
'
254254

255+
test_expect_success 'add --quiet' '
256+
git worktree add --quiet another-worktree master 2>actual &&
257+
test_must_be_empty actual
258+
'
259+
255260
test_expect_success 'local clone from linked checkout' '
256261
git clone --local here here-clone &&
257262
( cd here-clone && git fsck )

0 commit comments

Comments
 (0)