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 <eantoranz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Edmundo Carmona Antoranz committed Nov 1, 2015 at 15:19 UTC 870ebdb9c4facb55ed4817c5ff0968c0aadb7283
2 files changed +18 -2
Documentation/git-checkout.txt
+6
@@ -107,6 +107,12 @@ OPTIONS
107 --quiet::
108 Quiet, suppress feedback messages.
109
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 +
116 -f::
117 --force::
118 When switching branches, proceed even if the index or the
builtin/checkout.c
+12 -2
@@ -37,6 +37,7 @@ struct checkout_opts {
37 int overwrite_ignore;
38 int ignore_skipworktree;
39 int ignore_other_worktrees;
40 + int show_progress;
41
42 const char *new_branch;
43 const char *new_branch_force;
@@ -417,7 +418,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
418 opts.reset = 1;
419 opts.merge = 1;
420 opts.fn = oneway_merge;
420 - opts.verbose_update = !o->quiet && isatty(2);
421 + opts.verbose_update = o->show_progress;
422 opts.src_index = &the_index;
423 opts.dst_index = &the_index;
424 parse_tree(tree);
@@ -501,7 +502,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
502 topts.update = 1;
503 topts.merge = 1;
504 topts.gently = opts->merge && old->commit;
504 - topts.verbose_update = !opts->quiet && isatty(2);
505 + topts.verbose_update = opts->show_progress;
506 topts.fn = twoway_merge;
507 if (opts->overwrite_ignore) {
508 topts.dir = xcalloc(1, sizeof(*topts.dir));
@@ -1156,6 +1157,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1157 N_("second guess 'git checkout <no-such-branch>'")),
1158 OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
1159 N_("do not check if another worktree is holding the given ref")),
1160 + OPT_BOOL(0, "progress", &opts.show_progress, N_("force progress reporting")),
1161 OPT_END(),
1162 };
1163
@@ -1163,6 +1165,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1165 memset(&new, 0, sizeof(new));
1166 opts.overwrite_ignore = 1;
1167 opts.prefix = prefix;
1168 + opts.show_progress = -1;
1169
1170 gitmodules_config();
1171 git_config(git_checkout_config, &opts);
@@ -1172,6 +1175,13 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1175 argc = parse_options(argc, argv, prefix, options, checkout_usage,
1176 PARSE_OPT_KEEP_DASHDASH);
1177
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 +
1185 if (conflict_style) {
1186 opts.merge = 1; /* implied */
1187 git_xmerge_config("merge.conflictstyle", conflict_style, NULL);