diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-07-31 13:34:18 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-07-31 13:34:18 -0700 |
| commit | 90139ae37799b2ef48eb29fc8f9f984afd3c73db (patch) | |
| tree | bdaca521e0b86c3f2ca09ef8492ef1633b8eef8e /builtin/checkout.c | |
| parent | d71121c060dc1a76cb5be1674e4f719f5c58136e (diff) | |
| parent | d1e6c61272737926cd049a6126431fe9c12e4a54 (diff) | |
| download | git-90139ae37799b2ef48eb29fc8f9f984afd3c73db.tar.gz | |
Merge branch 'jc/checkout-no-op-switch-errors'
"git checkout --ours" (no other arguments) complained that the
option is incompatible with branch switching, which is technically
correct, but found confusing by some users. It now says that the
user needs to give pathspec to specify what paths to checkout.
* jc/checkout-no-op-switch-errors:
checkout: special case error messages during noop switching
Diffstat (limited to 'builtin/checkout.c')
| -rw-r--r-- | builtin/checkout.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 5769efaca0..0f21ddd2c6 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1572,6 +1572,10 @@ static void die_if_switching_to_a_branch_in_use(struct checkout_opts *opts, static int checkout_branch(struct checkout_opts *opts, struct branch_info *new_branch_info) { + int noop_switch = (!new_branch_info->name && + !opts->new_branch && + !opts->force_detach); + if (opts->pathspec.nr) die(_("paths cannot be used with switching branches")); @@ -1583,9 +1587,14 @@ static int checkout_branch(struct checkout_opts *opts, die(_("'%s' cannot be used with switching branches"), "--[no]-overlay"); - if (opts->writeout_stage) - die(_("'%s' cannot be used with switching branches"), - "--ours/--theirs"); + if (opts->writeout_stage) { + const char *msg; + if (noop_switch) + msg = _("'%s' needs the paths to check out"); + else + msg = _("'%s' cannot be used with switching branches"); + die(msg, "--ours/--theirs"); + } if (opts->force && opts->merge) die(_("'%s' cannot be used with '%s'"), "-f", "-m"); @@ -1612,10 +1621,8 @@ static int checkout_branch(struct checkout_opts *opts, die(_("Cannot switch branch to a non-commit '%s'"), new_branch_info->name); - if (!opts->switch_branch_doing_nothing_is_ok && - !new_branch_info->name && - !opts->new_branch && - !opts->force_detach) + if (noop_switch && + !opts->switch_branch_doing_nothing_is_ok) die(_("missing branch or commit argument")); if (!opts->implicit_detach && |
