Skip to content

Commit

Permalink
Merge branch 'ea/checkout-progress'
Browse files Browse the repository at this point in the history
"git checkout" did not follow the usual "--[no-]progress"
convention and implemented only "--quiet" that is essentially
a superset of "--no-progress".  Extend the command to support the
usual "--[no-]progress".

* ea/checkout-progress:
  checkout: add --progress option
  • Loading branch information
Junio C Hamano committed Nov 5, 2015
2 parents 848cdba + 870ebdb commit 6a38bd6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Documentation/git-checkout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ OPTIONS
--quiet::
Quiet, suppress feedback messages.

--[no-]progress::
Progress status is reported on the standard error stream
by default when it is attached to a terminal, unless `--quiet`
is specified. This flag enables progress reporting even if not
attached to a terminal, regardless of `--quiet`.

-f::
--force::
When switching branches, proceed even if the index or the
Expand Down
14 changes: 12 additions & 2 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct checkout_opts {
int overwrite_ignore;
int ignore_skipworktree;
int ignore_other_worktrees;
int show_progress;

const char *new_branch;
const char *new_branch_force;
Expand Down Expand Up @@ -417,7 +418,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
opts.reset = 1;
opts.merge = 1;
opts.fn = oneway_merge;
opts.verbose_update = !o->quiet && isatty(2);
opts.verbose_update = o->show_progress;
opts.src_index = &the_index;
opts.dst_index = &the_index;
parse_tree(tree);
Expand Down Expand Up @@ -501,7 +502,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
topts.update = 1;
topts.merge = 1;
topts.gently = opts->merge && old->commit;
topts.verbose_update = !opts->quiet && isatty(2);
topts.verbose_update = opts->show_progress;
topts.fn = twoway_merge;
if (opts->overwrite_ignore) {
topts.dir = xcalloc(1, sizeof(*topts.dir));
Expand Down Expand Up @@ -1156,13 +1157,15 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
N_("second guess 'git checkout <no-such-branch>'")),
OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
N_("do not check if another worktree is holding the given ref")),
OPT_BOOL(0, "progress", &opts.show_progress, N_("force progress reporting")),
OPT_END(),
};

memset(&opts, 0, sizeof(opts));
memset(&new, 0, sizeof(new));
opts.overwrite_ignore = 1;
opts.prefix = prefix;
opts.show_progress = -1;

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

if (opts.show_progress < 0) {
if (opts.quiet)
opts.show_progress = 0;
else
opts.show_progress = isatty(2);
}

if (conflict_style) {
opts.merge = 1; /* implied */
git_xmerge_config("merge.conflictstyle", conflict_style, NULL);
Expand Down

0 comments on commit 6a38bd6

Please sign in to comment.