Skip to content

Commit 870ebdb

Browse files
eantoranzgitster
authored andcommitted
checkout: add --progress option
Under normal circumstances, and like other git commands, git checkout will write progress info to stderr if attached to a terminal. This option allows progress to be forced even if not using a terminal. Also, progress can be skipped if using option --no-progress. Signed-off-by: Edmundo Carmona Antoranz <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b05c2f9 commit 870ebdb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Documentation/git-checkout.txt

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ OPTIONS
107107
--quiet::
108108
Quiet, suppress feedback messages.
109109

110+
--[no-]progress::
111+
Progress status is reported on the standard error stream
112+
by default when it is attached to a terminal, unless `--quiet`
113+
is specified. This flag enables progress reporting even if not
114+
attached to a terminal, regardless of `--quiet`.
115+
110116
-f::
111117
--force::
112118
When switching branches, proceed even if the index or the

builtin/checkout.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct checkout_opts {
3737
int overwrite_ignore;
3838
int ignore_skipworktree;
3939
int ignore_other_worktrees;
40+
int show_progress;
4041

4142
const char *new_branch;
4243
const char *new_branch_force;
@@ -417,7 +418,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
417418
opts.reset = 1;
418419
opts.merge = 1;
419420
opts.fn = oneway_merge;
420-
opts.verbose_update = !o->quiet && isatty(2);
421+
opts.verbose_update = o->show_progress;
421422
opts.src_index = &the_index;
422423
opts.dst_index = &the_index;
423424
parse_tree(tree);
@@ -501,7 +502,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
501502
topts.update = 1;
502503
topts.merge = 1;
503504
topts.gently = opts->merge && old->commit;
504-
topts.verbose_update = !opts->quiet && isatty(2);
505+
topts.verbose_update = opts->show_progress;
505506
topts.fn = twoway_merge;
506507
if (opts->overwrite_ignore) {
507508
topts.dir = xcalloc(1, sizeof(*topts.dir));
@@ -1156,13 +1157,15 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
11561157
N_("second guess 'git checkout <no-such-branch>'")),
11571158
OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
11581159
N_("do not check if another worktree is holding the given ref")),
1160+
OPT_BOOL(0, "progress", &opts.show_progress, N_("force progress reporting")),
11591161
OPT_END(),
11601162
};
11611163

11621164
memset(&opts, 0, sizeof(opts));
11631165
memset(&new, 0, sizeof(new));
11641166
opts.overwrite_ignore = 1;
11651167
opts.prefix = prefix;
1168+
opts.show_progress = -1;
11661169

11671170
gitmodules_config();
11681171
git_config(git_checkout_config, &opts);
@@ -1172,6 +1175,13 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
11721175
argc = parse_options(argc, argv, prefix, options, checkout_usage,
11731176
PARSE_OPT_KEEP_DASHDASH);
11741177

1178+
if (opts.show_progress < 0) {
1179+
if (opts.quiet)
1180+
opts.show_progress = 0;
1181+
else
1182+
opts.show_progress = isatty(2);
1183+
}
1184+
11751185
if (conflict_style) {
11761186
opts.merge = 1; /* implied */
11771187
git_xmerge_config("merge.conflictstyle", conflict_style, NULL);

0 commit comments

Comments
 (0)