From patchwork Tue Nov 27 16:52:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10700849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1155109C for ; Tue, 27 Nov 2018 16:53:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FBAF2C35E for ; Tue, 27 Nov 2018 16:53:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DE862C3C6; Tue, 27 Nov 2018 16:53:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35C6D2C35E for ; Tue, 27 Nov 2018 16:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731583AbeK1DwB (ORCPT ); Tue, 27 Nov 2018 22:52:01 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:45434 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729763AbeK1DwA (ORCPT ); Tue, 27 Nov 2018 22:52:00 -0500 Received: by mail-lf1-f68.google.com with SMTP id b20so16972720lfa.12 for ; Tue, 27 Nov 2018 08:53:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1POp7A0x0QOuoxW+bhpb80VjAWh8OmhLOYAqDBgTw1s=; b=B2tPlxMdG6SeNXHggZ84KrjfteeuJzrCKTIdy0faQdEp1H33xa8BR8aJbN49GoOsyO Dz7Y5kA10NECL7VkisRJnNhZHTzPMLqgA/3K7S1U0Fx4+RkhBkixuvrfho+7Vna7shgD AI5SAXCMEjx1BnFkUzwAKIgNR5p/3yiyBIEj6/30Ti7NQ2Ym1LQM8t7cN78qKFwt1hN8 aLSLjx04huOENJN+78TOnTMBHVbTZkR6/dPb6bqjOjgq7oEfN5Ppx1FiPb+GqyLYXEQD jlKWVhMgzx2Ax4S2NYPfhg0i4gNCILUdJzwn/nMriT75AwzJkYMy6UMIqKAIbwm/I8sw 6Vpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1POp7A0x0QOuoxW+bhpb80VjAWh8OmhLOYAqDBgTw1s=; b=fEJA8S2lGaKQfLudr1eV4tRAyAiVK/Fc43e3dca/n9W1kcVe/Aw4z2m7dfLtjgCrfP q/6j+a15Wxjp8KcrrPphSeDcdnPACSjDEMmU0MdcykTyMqCgUkaVe9iO+NbsfEIlEzPW BWzEMKLnVWYf+SqRO2JmAnBwP6roEeifMbbMzvLd9m9nO0CL6HXUuzIvCh3dvjh49UFx OapN8ddxc8H2i8JjgkKGNsfnm969ZSPhYuEI0HEIJCpoq9PfgEhVlp+6VJ3WgXez80cW NSUfoqiN8gghD8DHyhr6/FFXcU+Fj8zOEphfcNNrCjcadMPzSoWQVQZHJsJsf0bIqle6 YO+Q== X-Gm-Message-State: AGRZ1gIiaiARbJWymYvpQ7sVl0lQSwo0Fu3wBQWaUqrPEjWKkStMyyZp gAhbKa2uiyxx+/L/alx9ju+0zMwd X-Google-Smtp-Source: AJdET5dc+FdirtAv8L3fGrsMWe1nFnShyOmXfHiz28KDdyFZ9XRgNkJ85UDIBmL8/FVtRO94nYAGbA== X-Received: by 2002:a19:5402:: with SMTP id i2mr18717854lfb.128.1543337608603; Tue, 27 Nov 2018 08:53:28 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g66sm694016lfe.42.2018.11.27.08.53.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:53:27 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, Stefan Beller , t.gummerer@gmail.com Subject: [PATCH v2 1/7] parse-options: allow parse_options_concat(NULL, options) Date: Tue, 27 Nov 2018 17:52:05 +0100 Message-Id: <20181127165211.24763-2-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1327.g328c130451.dirty In-Reply-To: <20181127165211.24763-1-pclouds@gmail.com> References: <20181120174554.GA29910@duynguyen.home> <20181127165211.24763-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is currently no caller that calls this function with "a" being NULL. But it will be introduced shortly. It is used to construct the option array from scratch, e.g. struct parse_options opts = NULL; opts = parse_options_concat(opts, opts_1); opts = parse_options_concat(opts, opts_2); Signed-off-by: Nguyễn Thái Ngọc Duy --- parse-options-cb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse-options-cb.c b/parse-options-cb.c index 8c9edce52f..c609d52926 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -126,7 +126,7 @@ struct option *parse_options_concat(struct option *a, struct option *b) struct option *ret; size_t i, a_len = 0, b_len = 0; - for (i = 0; a[i].type != OPTION_END; i++) + for (i = 0; a && a[i].type != OPTION_END; i++) a_len++; for (i = 0; b[i].type != OPTION_END; i++) b_len++; From patchwork Tue Nov 27 16:52:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10700851 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2244109C for ; Tue, 27 Nov 2018 16:53:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFFB82B46C for ; Tue, 27 Nov 2018 16:53:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3B6F2B6C1; Tue, 27 Nov 2018 16:53:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B90D7287CF for ; Tue, 27 Nov 2018 16:53:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731588AbeK1DwC (ORCPT ); Tue, 27 Nov 2018 22:52:02 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:33779 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731294AbeK1DwC (ORCPT ); Tue, 27 Nov 2018 22:52:02 -0500 Received: by mail-lj1-f194.google.com with SMTP id v1-v6so20734940ljd.0 for ; Tue, 27 Nov 2018 08:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E5TO7/llHmklN9FyEnSwwtvTdG83hVgNWxa8P3ft6iw=; b=a9Z95MAza51+W1UkXylTGB6k0IX6Wvavljb/N0mkfpDG1FVYhIS7WS8Viy+hjx/Dx5 Ula955cAvcMiRpm/MU38Oltpew0XdJS0FsWDAsWvRgSjcl62paZOYOgI2JJy6C2oKkkv ztY7piTqFP+9KuY26+4XpzzkTnhkn9QU3N1ummGm69lGc5Q6q6DsZPI7SK0jYP6z7ulK gyA2qIcP/mrBW5t+D6JKOJPnzw8pv1RNVtvRcyTknlxD6X4Sle1mlXr7EzAR4fzbmQ18 gESB1LrJiTHdMf5DDCeXAxtMC8ATOaDnHPLV8AVxZDRLOdH750k9JAm8Yh6Nmwc67mBd Mj1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E5TO7/llHmklN9FyEnSwwtvTdG83hVgNWxa8P3ft6iw=; b=JhlLIXjEn961yTlwUkTjtO3+zYl3VoOVhl5efDQCtTDnOoggr5nrFCYqf5eiNxCP+Z WT4nMOZVavfjXrmWMyvoypsXvB3NURn7Yk1NkK0EqYZ/EpK6aQMMye7c353QVOWl7VvK +nrVtwtqME6ZWzsLwhx3bIc1lqM5CL37QXK6YgytS1C4DhBXSJ0MbaNP3N0if14+sUfh caiXTJU/V7D/cSK9H6MAK33w6cU8h6KtGhSg6EzFWOio52dzwoEcAkWQGxocYh3iM4l6 Kwv1hPn9MDxqrF0cId6ufNUizag02UxHZn9FhCavcK1Ge44ZISHjRm3WZILtAhe0VNxu 7a6w== X-Gm-Message-State: AA+aEWapAja5VUxuuo/DBiQcJuqnTO/kuSKcQS+I6fVFVh9s8jMio09s b8mxrAItjNswYPO7MprgyS2vNSM+ X-Google-Smtp-Source: AFSGD/XKyZ3URTooGVYGwzYNSxroNSxC1cWY8dEeXDcBH+Fn4Rv8od8G3YQX+XQY3B2Xg9hU2jN+EQ== X-Received: by 2002:a2e:9783:: with SMTP id y3-v6mr19964070lji.167.1543337609785; Tue, 27 Nov 2018 08:53:29 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g66sm694016lfe.42.2018.11.27.08.53.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:53:29 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, Stefan Beller , t.gummerer@gmail.com Subject: [PATCH v2 2/7] checkout: make "opts" in cmd_checkout() a pointer Date: Tue, 27 Nov 2018 17:52:06 +0100 Message-Id: <20181127165211.24763-3-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1327.g328c130451.dirty In-Reply-To: <20181127165211.24763-1-pclouds@gmail.com> References: <20181120174554.GA29910@duynguyen.home> <20181127165211.24763-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP "opts" will soon be moved out of cmd_checkout(). To keep changes in that patch smaller, convert "opts" to a pointer and keep the real thing behind "real_opts". Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 109 +++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index acdafc6e4c..31245c1eb4 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1225,76 +1225,77 @@ static int checkout_branch(struct checkout_opts *opts, int cmd_checkout(int argc, const char **argv, const char *prefix) { - struct checkout_opts opts; + struct checkout_opts real_opts; + struct checkout_opts *opts = &real_opts; struct branch_info new_branch_info; char *conflict_style = NULL; int dwim_new_local_branch = 1; int dwim_remotes_matched = 0; struct option options[] = { - OPT__QUIET(&opts.quiet, N_("suppress progress reporting")), - OPT_STRING('b', NULL, &opts.new_branch, N_("branch"), + OPT__QUIET(&opts->quiet, N_("suppress progress reporting")), + OPT_STRING('b', NULL, &opts->new_branch, N_("branch"), N_("create and checkout a new branch")), - OPT_STRING('B', NULL, &opts.new_branch_force, N_("branch"), + OPT_STRING('B', NULL, &opts->new_branch_force, N_("branch"), N_("create/reset and checkout a branch")), - OPT_BOOL('l', NULL, &opts.new_branch_log, N_("create reflog for new branch")), - OPT_BOOL(0, "detach", &opts.force_detach, N_("detach HEAD at named commit")), - OPT_SET_INT('t', "track", &opts.track, N_("set upstream info for new branch"), + OPT_BOOL('l', NULL, &opts->new_branch_log, N_("create reflog for new branch")), + OPT_BOOL(0, "detach", &opts->force_detach, N_("detach HEAD at named commit")), + OPT_SET_INT('t', "track", &opts->track, N_("set upstream info for new branch"), BRANCH_TRACK_EXPLICIT), - OPT_STRING(0, "orphan", &opts.new_orphan_branch, N_("new-branch"), N_("new unparented branch")), - OPT_SET_INT_F('2', "ours", &opts.writeout_stage, + OPT_STRING(0, "orphan", &opts->new_orphan_branch, N_("new-branch"), N_("new unparented branch")), + OPT_SET_INT_F('2', "ours", &opts->writeout_stage, N_("checkout our version for unmerged files"), 2, PARSE_OPT_NONEG), - OPT_SET_INT_F('3', "theirs", &opts.writeout_stage, + OPT_SET_INT_F('3', "theirs", &opts->writeout_stage, N_("checkout their version for unmerged files"), 3, PARSE_OPT_NONEG), - OPT__FORCE(&opts.force, N_("force checkout (throw away local modifications)"), + OPT__FORCE(&opts->force, N_("force checkout (throw away local modifications)"), PARSE_OPT_NOCOMPLETE), - OPT_BOOL('m', "merge", &opts.merge, N_("perform a 3-way merge with the new branch")), - OPT_BOOL_F(0, "overwrite-ignore", &opts.overwrite_ignore, + OPT_BOOL('m', "merge", &opts->merge, N_("perform a 3-way merge with the new branch")), + OPT_BOOL_F(0, "overwrite-ignore", &opts->overwrite_ignore, N_("update ignored files (default)"), PARSE_OPT_NOCOMPLETE), OPT_STRING(0, "conflict", &conflict_style, N_("style"), N_("conflict style (merge or diff3)")), - OPT_BOOL('p', "patch", &opts.patch_mode, N_("select hunks interactively")), - OPT_BOOL(0, "ignore-skip-worktree-bits", &opts.ignore_skipworktree, + OPT_BOOL('p', "patch", &opts->patch_mode, N_("select hunks interactively")), + OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree, N_("do not limit pathspecs to sparse entries only")), OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch, N_("second guess 'git checkout '")), - OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees, + OPT_BOOL(0, "ignore-other-worktrees", &opts->ignore_other_worktrees, N_("do not check if another worktree is holding the given ref")), { OPTION_CALLBACK, 0, "recurse-submodules", NULL, "checkout", "control recursive updating of submodules", PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater }, - OPT_BOOL(0, "progress", &opts.show_progress, N_("force progress reporting")), + OPT_BOOL(0, "progress", &opts->show_progress, N_("force progress reporting")), OPT_END(), }; - memset(&opts, 0, sizeof(opts)); + memset(opts, 0, sizeof(*opts)); memset(&new_branch_info, 0, sizeof(new_branch_info)); - opts.overwrite_ignore = 1; - opts.prefix = prefix; - opts.show_progress = -1; + opts->overwrite_ignore = 1; + opts->prefix = prefix; + opts->show_progress = -1; - git_config(git_checkout_config, &opts); + git_config(git_checkout_config, opts); - opts.track = BRANCH_TRACK_UNSPECIFIED; + opts->track = BRANCH_TRACK_UNSPECIFIED; 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; + if (opts->show_progress < 0) { + if (opts->quiet) + opts->show_progress = 0; else - opts.show_progress = isatty(2); + opts->show_progress = isatty(2); } if (conflict_style) { - opts.merge = 1; /* implied */ + opts->merge = 1; /* implied */ git_xmerge_config("merge.conflictstyle", conflict_style, NULL); } - if ((!!opts.new_branch + !!opts.new_branch_force + !!opts.new_orphan_branch) > 1) + if ((!!opts->new_branch + !!opts->new_branch_force + !!opts->new_orphan_branch) > 1) die(_("-b, -B and --orphan are mutually exclusive")); /* @@ -1302,14 +1303,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) * and new_branch_force and new_orphan_branch will tell us which one of * -b/-B/--orphan is being used. */ - if (opts.new_branch_force) - opts.new_branch = opts.new_branch_force; + if (opts->new_branch_force) + opts->new_branch = opts->new_branch_force; - if (opts.new_orphan_branch) - opts.new_branch = opts.new_orphan_branch; + if (opts->new_orphan_branch) + opts->new_branch = opts->new_orphan_branch; /* --track without -b/-B/--orphan should DWIM */ - if (opts.track != BRANCH_TRACK_UNSPECIFIED && !opts.new_branch) { + if (opts->track != BRANCH_TRACK_UNSPECIFIED && !opts->new_branch) { const char *argv0 = argv[0]; if (!argc || !strcmp(argv0, "--")) die(_("--track needs a branch name")); @@ -1318,7 +1319,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) argv0 = strchr(argv0, '/'); if (!argv0 || !argv0[1]) die(_("missing branch name; try -b")); - opts.new_branch = argv0 + 1; + opts->new_branch = argv0 + 1; } /* @@ -1337,56 +1338,56 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) if (argc) { struct object_id rev; int dwim_ok = - !opts.patch_mode && + !opts->patch_mode && dwim_new_local_branch && - opts.track == BRANCH_TRACK_UNSPECIFIED && - !opts.new_branch; + opts->track == BRANCH_TRACK_UNSPECIFIED && + !opts->new_branch; int n = parse_branchname_arg(argc, argv, dwim_ok, - &new_branch_info, &opts, &rev, + &new_branch_info, opts, &rev, &dwim_remotes_matched); argv += n; argc -= n; } if (argc) { - parse_pathspec(&opts.pathspec, 0, - opts.patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0, + parse_pathspec(&opts->pathspec, 0, + opts->patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0, prefix, argv); - if (!opts.pathspec.nr) + if (!opts->pathspec.nr) die(_("invalid path specification")); /* * Try to give more helpful suggestion. * new_branch && argc > 1 will be caught later. */ - if (opts.new_branch && argc == 1) + if (opts->new_branch && argc == 1) die(_("'%s' is not a commit and a branch '%s' cannot be created from it"), - argv[0], opts.new_branch); + argv[0], opts->new_branch); - if (opts.force_detach) + if (opts->force_detach) die(_("git checkout: --detach does not take a path argument '%s'"), argv[0]); - if (1 < !!opts.writeout_stage + !!opts.force + !!opts.merge) + if (1 < !!opts->writeout_stage + !!opts->force + !!opts->merge) die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\n" "checking out of the index.")); } - if (opts.new_branch) { + if (opts->new_branch) { struct strbuf buf = STRBUF_INIT; - if (opts.new_branch_force) - opts.branch_exists = validate_branchname(opts.new_branch, &buf); + if (opts->new_branch_force) + opts->branch_exists = validate_branchname(opts->new_branch, &buf); else - opts.branch_exists = - validate_new_branchname(opts.new_branch, &buf, 0); + opts->branch_exists = + validate_new_branchname(opts->new_branch, &buf, 0); strbuf_release(&buf); } UNLEAK(opts); - if (opts.patch_mode || opts.pathspec.nr) { - int ret = checkout_paths(&opts, new_branch_info.name); + if (opts->patch_mode || opts->pathspec.nr) { + int ret = checkout_paths(opts, new_branch_info.name); if (ret && dwim_remotes_matched > 1 && advice_checkout_ambiguous_remote_branch_name) advise(_("'%s' matched more than one remote tracking branch.\n" @@ -1405,6 +1406,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) dwim_remotes_matched); return ret; } else { - return checkout_branch(&opts, &new_branch_info); + return checkout_branch(opts, &new_branch_info); } } From patchwork Tue Nov 27 16:52:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10700861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A972A14BD for ; Tue, 27 Nov 2018 16:53:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 994DC2888B for ; Tue, 27 Nov 2018 16:53:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97A6B285B0; Tue, 27 Nov 2018 16:53:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34C672B986 for ; Tue, 27 Nov 2018 16:53:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731589AbeK1DwD (ORCPT ); Tue, 27 Nov 2018 22:52:03 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:44203 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729763AbeK1DwC (ORCPT ); Tue, 27 Nov 2018 22:52:02 -0500 Received: by mail-lf1-f67.google.com with SMTP id z13so16973355lfe.11 for ; Tue, 27 Nov 2018 08:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4xEYQMiIKagrO5r2UaaIWiWV3vExbIPwQ5ntLG3rXpw=; b=bmmiuSptpwjFlg2diPrR/1STyCJq0j8UwR6vWgvJRD8ojljVZuWFDwKUG0YjnqabUc iHL0WmyZZc7Lxwf982hph/MIq6zvHG776lFbrykRkPJXpjOcdSsEvurezFC7UmRLXJwY Fqg2EbVVKPHbfLh4lnSqzX8H/pJvg8kkk21fdazohHKMsAmwQ8p1TKmwEDALieXsnf2W nZd5VHCiRMFcjSiEsCL+CFKxqpbWmheqr2MRmjv4VwQQv1GMYWQ4cda7q3VFS9kVWUZE JID068JoKJm9aS01bb//iBNo60TnpLlI+mrDocE5xcTm3iZJ1zKsMMphO0pfn3ZwxxK8 X4HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4xEYQMiIKagrO5r2UaaIWiWV3vExbIPwQ5ntLG3rXpw=; b=M9OjDaQp6ur9V0r36QU58zJhO/R4pZ0opBA1Zl0n2krsvNOyNdHdUqkgkBmfWgDcnn 57irqBjNdEXWw0VHUsHHpGwqMNyZVG9AQ2IxHL6+/gCaWSjHIFV+j38ZJTTbHViZpOQs lw0bGlJ23Jj2jtv+w64KyHPyJBNIl64two385KvUkEEGfMtgEifjQfb6P5fSAjCC/eGv /FFoJFugFJxg1gMuaF07AU+uFPA9f79a2pDcsBnsp+ej7wHLEE+M32gv0VnrS5f/WnpF 3kbxZfSfVU1XL+CodXaMWZrbvCTfAIJY1KGWj0vAtpcjGBQn/PRvugcVbThqpzUYjVKp p29Q== X-Gm-Message-State: AGRZ1gKxgCYKFZmP7pPsAa4+UCFxCiHi/OPB1k2bF5mcP+4fhRJxRxwO zuF4jCsMz6ZM1AAmyKSkD/M= X-Google-Smtp-Source: AJdET5eCvitBqOg5MoFceB30oJUdTmbNR+r7U0c8YnqakIklLxf2X6vMNsVkEYyF9kkxdsjYELDJag== X-Received: by 2002:a19:1019:: with SMTP id f25mr18844664lfi.54.1543337610791; Tue, 27 Nov 2018 08:53:30 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g66sm694016lfe.42.2018.11.27.08.53.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:53:30 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, Stefan Beller , t.gummerer@gmail.com Subject: [PATCH v2 3/7] checkout: move 'confict_style' to checkout_opts Date: Tue, 27 Nov 2018 17:52:07 +0100 Message-Id: <20181127165211.24763-4-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1327.g328c130451.dirty In-Reply-To: <20181127165211.24763-1-pclouds@gmail.com> References: <20181120174554.GA29910@duynguyen.home> <20181127165211.24763-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 31245c1eb4..211a347a0c 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -55,6 +55,7 @@ struct checkout_opts { int new_branch_log; enum branch_track track; struct diff_options diff_options; + char *conflict_style; int branch_exists; const char *prefix; @@ -1228,7 +1229,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) struct checkout_opts real_opts; struct checkout_opts *opts = &real_opts; struct branch_info new_branch_info; - char *conflict_style = NULL; int dwim_new_local_branch = 1; int dwim_remotes_matched = 0; struct option options[] = { @@ -1254,7 +1254,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) OPT_BOOL_F(0, "overwrite-ignore", &opts->overwrite_ignore, N_("update ignored files (default)"), PARSE_OPT_NOCOMPLETE), - OPT_STRING(0, "conflict", &conflict_style, N_("style"), + OPT_STRING(0, "conflict", &opts->conflict_style, N_("style"), N_("conflict style (merge or diff3)")), OPT_BOOL('p', "patch", &opts->patch_mode, N_("select hunks interactively")), OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree, @@ -1290,9 +1290,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) opts->show_progress = isatty(2); } - if (conflict_style) { + if (opts->conflict_style) { opts->merge = 1; /* implied */ - git_xmerge_config("merge.conflictstyle", conflict_style, NULL); + git_xmerge_config("merge.conflictstyle", opts->conflict_style, NULL); } if ((!!opts->new_branch + !!opts->new_branch_force + !!opts->new_orphan_branch) > 1) From patchwork Tue Nov 27 16:52:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10700857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6134109C for ; Tue, 27 Nov 2018 16:53:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D52CF2B46C for ; Tue, 27 Nov 2018 16:53:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D35802B6CF; Tue, 27 Nov 2018 16:53:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 709EF2B46C for ; Tue, 27 Nov 2018 16:53:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731609AbeK1DwK (ORCPT ); Tue, 27 Nov 2018 22:52:10 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:42199 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731585AbeK1DwD (ORCPT ); Tue, 27 Nov 2018 22:52:03 -0500 Received: by mail-lj1-f194.google.com with SMTP id l15-v6so20689843lja.9 for ; Tue, 27 Nov 2018 08:53:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xwVm2UlEISq0mOnHmT1GHMrl1Qe9fbMmKAMF4l/yts8=; b=hs4RESacump7uOQIUhfZMGNzFMHM1DzOeoBTzO46WV98u4QAqpo0dP/lFEL5M8if8d DrhesZXdi72GGkSseHp9oi9/EOVOOjM6atS/XXhDp4HVNY7LDlYJ0mvrSUV5O8YqP78c J5EecRadNURVMMM+xw/v5yRTTQQXFfV6wBKt7mA7dhdstmRh6IxkflpT9PeYXXJB9AMR TiPL03q4ixM3vVwKh5U1XM6v7ZD9Wtr+5Y2N173SL0CLIOZsJJd0hgHgIn7KEkdTXYFw ygbJDtI60DOiws5N/TgqtyD2KuwtxxaT5es75P/ggNO8mBGDQBE4eIv9e3iucZHewM3v F9jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xwVm2UlEISq0mOnHmT1GHMrl1Qe9fbMmKAMF4l/yts8=; b=ncpvhLWjKIhdan3hOJC/HTX83sNS6it1bMRcXNjOykUebrmkF7kU9PZxnydTOcSgy2 eKR36GN+XBr9Qunz9mEmNM2YFdLGKUqs11USQwmY1zhNMrWKk5Dkks3TJypeQDlZSY+p Y3SmLiZvgz/rY8IuqOrdLjDkO4+ooaBYsBA2rvjKORWCOXxxoymaIjk83QW+h5A9MS8g JwnNeYsPi4+bTzUA7oOWgTQbXD1piFzDCXdjxCk8epyqjsKTtJat1vUsHUk90wLnnI5k ZkWDkx3XbDfuCxTnmG/UWJw/AcQNwAJ8/FhKtB4RoL/5xciHB/H/Dtgb0u1AYsZHhR7Y VTpg== X-Gm-Message-State: AA+aEWYrpv9SWqDhGKMfAFmgIST1cxqgRnilMzABp6vXzvs8FJDVd7rC PJ2ndpIUAkUVlomjT/Q1GXI= X-Google-Smtp-Source: AFSGD/U0hCKufxnvsC6vjoYCNOIc6x88YvBTgCSMp7VLACr8/TMXKoOxmArdyfto9lifU6cEokMHdg== X-Received: by 2002:a2e:99d7:: with SMTP id l23-v6mr19565108ljj.165.1543337611892; Tue, 27 Nov 2018 08:53:31 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g66sm694016lfe.42.2018.11.27.08.53.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:53:31 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, Stefan Beller , t.gummerer@gmail.com Subject: [PATCH v2 4/7] checkout: move dwim_new_local_branch to checkout_opts Date: Tue, 27 Nov 2018 17:52:08 +0100 Message-Id: <20181127165211.24763-5-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1327.g328c130451.dirty In-Reply-To: <20181127165211.24763-1-pclouds@gmail.com> References: <20181120174554.GA29910@duynguyen.home> <20181127165211.24763-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 211a347a0c..a50c51f287 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -44,6 +44,8 @@ struct checkout_opts { int ignore_skipworktree; int ignore_other_worktrees; int show_progress; + int dwim_new_local_branch; + /* * If new checkout options are added, skip_merge_working_tree * should be updated accordingly. @@ -1229,7 +1231,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) struct checkout_opts real_opts; struct checkout_opts *opts = &real_opts; struct branch_info new_branch_info; - int dwim_new_local_branch = 1; int dwim_remotes_matched = 0; struct option options[] = { OPT__QUIET(&opts->quiet, N_("suppress progress reporting")), @@ -1259,7 +1260,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) OPT_BOOL('p', "patch", &opts->patch_mode, N_("select hunks interactively")), OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree, N_("do not limit pathspecs to sparse entries only")), - OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch, + OPT_HIDDEN_BOOL(0, "guess", &opts->dwim_new_local_branch, N_("second guess 'git checkout '")), OPT_BOOL(0, "ignore-other-worktrees", &opts->ignore_other_worktrees, N_("do not check if another worktree is holding the given ref")), @@ -1275,6 +1276,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) opts->overwrite_ignore = 1; opts->prefix = prefix; opts->show_progress = -1; + opts->dwim_new_local_branch = 1; git_config(git_checkout_config, opts); @@ -1339,7 +1341,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) struct object_id rev; int dwim_ok = !opts->patch_mode && - dwim_new_local_branch && + opts->dwim_new_local_branch && opts->track == BRANCH_TRACK_UNSPECIFIED && !opts->new_branch; int n = parse_branchname_arg(argc, argv, dwim_ok, From patchwork Tue Nov 27 16:52:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10700853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3610A1869 for ; Tue, 27 Nov 2018 16:53:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22FF22B6E3 for ; Tue, 27 Nov 2018 16:53:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 214B62B945; Tue, 27 Nov 2018 16:53:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83DA42B99D for ; Tue, 27 Nov 2018 16:53:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731603AbeK1DwG (ORCPT ); Tue, 27 Nov 2018 22:52:06 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:36282 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731584AbeK1DwF (ORCPT ); Tue, 27 Nov 2018 22:52:05 -0500 Received: by mail-lj1-f195.google.com with SMTP id g11-v6so20714209ljk.3 for ; Tue, 27 Nov 2018 08:53:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/nf+jUR8CWRte6uj5zdCHr3bOgxkxHpatbZyBtnm020=; b=msW/x+TKqOMpq6GCz1X9dmfgu/X5l1uZ8obLqKbCclMMtMZp1PgTzRfh7I1tyUj0VQ vRXWUlZwb14bh5lWVRzHniy6CcyzDpEoWC6WYv/iEFo9ZuJNTHmtIHmtF1MP+Cu+owcX FfFQxLqPWZkfeP96BzNR0Jf3X/7Qyl224IR75NKz5oDA3nwW4KcBvhaDcdsWxNvIGk1s s/OJAL5tyoBSGnhS1NuY4wKu8RF1VBHPLb2zvXC/QuAKU1ueyRtCUYLq4Vh2dNh1ZAVy 18SJTsDJ0QHxuv8TqDfD/WtZHVWTEn4G7zzyBlacR2eVpJ+KZmd1IptfBGGULpKOUbem bDNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/nf+jUR8CWRte6uj5zdCHr3bOgxkxHpatbZyBtnm020=; b=HgNAUzucYVXYNOMWhYhMEecdmQ3fIbsHFo1iaXysRo5meecKTG7ZwbBNOiF1x6m9hc CNWjnGU8DM2hbYoDI4qzAorD40NORoIJcmT51zKyyrypoxI0TigAfUPr7IsXoTdzW+v9 ITaJqVnuRgmO6VadGOzc50/3lIkvNrbuzlO5ZprnE4fRvrLDyewDlSpQ0dEZPwEa+6K3 1dmo84n0D2vCHB1N/reRRcf23i1kHIiCeRS/q8fg39KM+p5Fg4xhG9Oc62MmqxsHlmJR GoEjo3gi1q1XbVtxE5zcdpfWg9x2U6jq0LmsRZh+SUypHQ/sH1lnNQugwtIHP3AUkMZF RcUw== X-Gm-Message-State: AA+aEWbDpSRcruOCIhbdwAc56A4py+icWgBvd37RTp0pQvBmY95A3l8x O0BwzgZ+DAqAuJeC9sJmtC4= X-Google-Smtp-Source: AFSGD/XKH3cHFIpgCW7g3IA9i0qV9UNBebF4efkr2g245yjs3mLjM+hW9mjJuzV/XUdSS+B4hJX7nw== X-Received: by 2002:a2e:9dcb:: with SMTP id x11-v6mr947055ljj.158.1543337613501; Tue, 27 Nov 2018 08:53:33 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g66sm694016lfe.42.2018.11.27.08.53.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:53:32 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, Stefan Beller , t.gummerer@gmail.com Subject: [PATCH v2 5/7] checkout: split options[] array in three pieces Date: Tue, 27 Nov 2018 17:52:09 +0100 Message-Id: <20181127165211.24763-6-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1327.g328c130451.dirty In-Reply-To: <20181127165211.24763-1-pclouds@gmail.com> References: <20181120174554.GA29910@duynguyen.home> <20181127165211.24763-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a preparation step for introducing new commands that do parts of what checkout does. There will be two new commands, one is about switching branches, detaching HEAD... one about checking out paths. These share the a subset of command line options. The rest of command line options are separate. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 80 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index a50c51f287..d9dbd2d40d 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1226,14 +1226,32 @@ static int checkout_branch(struct checkout_opts *opts, return switch_branches(opts, new_branch_info); } -int cmd_checkout(int argc, const char **argv, const char *prefix) +static struct option *add_common_options(struct checkout_opts *opts, + struct option *prevopts) { - struct checkout_opts real_opts; - struct checkout_opts *opts = &real_opts; - struct branch_info new_branch_info; - int dwim_remotes_matched = 0; struct option options[] = { OPT__QUIET(&opts->quiet, N_("suppress progress reporting")), + OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree, + N_("do not limit pathspecs to sparse entries only")), + { OPTION_CALLBACK, 0, "recurse-submodules", NULL, + "checkout", "control recursive updating of submodules", + PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater }, + OPT_BOOL(0, "progress", &opts->show_progress, N_("force progress reporting")), + OPT__FORCE(&opts->force, N_("force checkout (throw away local modifications)"), + PARSE_OPT_NOCOMPLETE), + OPT_STRING(0, "conflict", &opts->conflict_style, N_("style"), + N_("conflict style (merge or diff3)")), + OPT_END() + }; + struct option *newopts = parse_options_concat(prevopts, options); + free(prevopts); + return newopts; +} + +static struct option *add_switch_branch_options(struct checkout_opts *opts, + struct option *prevopts) +{ + struct option options[] = { OPT_STRING('b', NULL, &opts->new_branch, N_("branch"), N_("create and checkout a new branch")), OPT_STRING('B', NULL, &opts->new_branch_force, N_("branch"), @@ -1243,33 +1261,43 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) OPT_SET_INT('t', "track", &opts->track, N_("set upstream info for new branch"), BRANCH_TRACK_EXPLICIT), OPT_STRING(0, "orphan", &opts->new_orphan_branch, N_("new-branch"), N_("new unparented branch")), + OPT_BOOL('m', "merge", &opts->merge, N_("perform a 3-way merge with the new branch")), + OPT_HIDDEN_BOOL(0, "guess", &opts->dwim_new_local_branch, + N_("second guess 'git checkout '")), + OPT_BOOL(0, "ignore-other-worktrees", &opts->ignore_other_worktrees, + N_("do not check if another worktree is holding the given ref")), + OPT_END() + }; + struct option *newopts = parse_options_concat(prevopts, options); + free(prevopts); + return newopts; +} + +static struct option *add_checkout_path_options(struct checkout_opts *opts, + struct option *prevopts) +{ + struct option options[] = { OPT_SET_INT_F('2', "ours", &opts->writeout_stage, N_("checkout our version for unmerged files"), 2, PARSE_OPT_NONEG), OPT_SET_INT_F('3', "theirs", &opts->writeout_stage, N_("checkout their version for unmerged files"), 3, PARSE_OPT_NONEG), - OPT__FORCE(&opts->force, N_("force checkout (throw away local modifications)"), - PARSE_OPT_NOCOMPLETE), - OPT_BOOL('m', "merge", &opts->merge, N_("perform a 3-way merge with the new branch")), - OPT_BOOL_F(0, "overwrite-ignore", &opts->overwrite_ignore, - N_("update ignored files (default)"), - PARSE_OPT_NOCOMPLETE), - OPT_STRING(0, "conflict", &opts->conflict_style, N_("style"), - N_("conflict style (merge or diff3)")), OPT_BOOL('p', "patch", &opts->patch_mode, N_("select hunks interactively")), - OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree, - N_("do not limit pathspecs to sparse entries only")), - OPT_HIDDEN_BOOL(0, "guess", &opts->dwim_new_local_branch, - N_("second guess 'git checkout '")), - OPT_BOOL(0, "ignore-other-worktrees", &opts->ignore_other_worktrees, - N_("do not check if another worktree is holding the given ref")), - { OPTION_CALLBACK, 0, "recurse-submodules", NULL, - "checkout", "control recursive updating of submodules", - PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater }, - OPT_BOOL(0, "progress", &opts->show_progress, N_("force progress reporting")), - OPT_END(), + OPT_END() }; + struct option *newopts = parse_options_concat(prevopts, options); + free(prevopts); + return newopts; +} + +int cmd_checkout(int argc, const char **argv, const char *prefix) +{ + struct checkout_opts real_opts; + struct checkout_opts *opts = &real_opts; + struct branch_info new_branch_info; + int dwim_remotes_matched = 0; + struct option *options = NULL; memset(opts, 0, sizeof(*opts)); memset(&new_branch_info, 0, sizeof(new_branch_info)); @@ -1282,6 +1310,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) opts->track = BRANCH_TRACK_UNSPECIFIED; + options = add_common_options(opts, options); + options = add_switch_branch_options(opts, options); + options = add_checkout_path_options(opts, options); + argc = parse_options(argc, argv, prefix, options, checkout_usage, PARSE_OPT_KEEP_DASHDASH); From patchwork Tue Nov 27 16:52:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10700855 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37E8714BD for ; Tue, 27 Nov 2018 16:53:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2654E2BD0F for ; Tue, 27 Nov 2018 16:53:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B3B62BD1F; Tue, 27 Nov 2018 16:53:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B93EE2BB20 for ; Tue, 27 Nov 2018 16:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731606AbeK1DwI (ORCPT ); Tue, 27 Nov 2018 22:52:08 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:34158 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731580AbeK1DwH (ORCPT ); Tue, 27 Nov 2018 22:52:07 -0500 Received: by mail-lj1-f195.google.com with SMTP id u6-v6so20693790ljd.1 for ; Tue, 27 Nov 2018 08:53:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6brQhIwpV2Fs+CmMlcXl/1k5MLHmasxGxy0XJf2ZpGU=; b=jwisNU4Qcl+fQeXy7m6orkKWcDmEHjhap2MnThcHiX4pd/2q9VNiG0w5dPvAPxXR3p ndn7GE09fJoSOvLNOsDbdipA6nCtHmJs9Uz9Ks4gkIrOpMDtd76GdWvh7A19cb8YX5Ss n17hwFAfocVe3CSVvg4MYjrYXUfnYorVMqLMRqBV8AZGRNo2RIdMmLoywYRUsVDKy67k L0hzzyupsv9hHYvB+PNCDcCi6J5y9JXw9Z8RNmC2oCRjDyRQJBeTp7yytlL/pB9bw0fm L4aCmKavAQsIJdoeBxWPz4xU169xw2yEqmo/lBLeZ4kfVtM99jFEqREwDIRzpSYE0bWD U5iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6brQhIwpV2Fs+CmMlcXl/1k5MLHmasxGxy0XJf2ZpGU=; b=VxPi1ZawnycNeaCXSIEcz952awXakpGxnstMJKVIv9ikn7gzMLXlMEZJwPLFippSo4 m2zU4Ed9n14xGjWhXzQA4TFVRGjf69uRwsatynEKTtlK+mfVrQf9T6m44C6mDse9m4pj ozGtHTEhv38lxeHlVprZX8t+6+wEmoTzJpN+lHcw2gC4SqzrP9qmuZbuSCItdYkeXhv3 LfW7TMzET+YZgNvvk85rPxBWXnWSqtY509z0Y17ISWEu1V8VF8c+FlXGHv3YuVPbLfuE 3jFQcErOImVxAZS4hCLanMlOWbVA4Sxxbargz+J87+3ePHmW+QHUn/sWrgBaOEb2m5BT 2B2A== X-Gm-Message-State: AA+aEWYI0XzfWwB4w+Tm3vjuiImK8SK8HPQayloK7btfMmyBRBZuUuoc dZPD5gKRXAzdB+84EpasGAbqMKI0 X-Google-Smtp-Source: AJdET5fSAmID4Nbm2BQro6QlM4wCE0Pam7oDzIAZrNXoknQieTbrSoqntMwHMhYOUMrtvcWnvj/n/Q== X-Received: by 2002:a2e:9107:: with SMTP id m7-v6mr20375435ljg.23.1543337614712; Tue, 27 Nov 2018 08:53:34 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g66sm694016lfe.42.2018.11.27.08.53.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:53:33 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, Stefan Beller , t.gummerer@gmail.com Subject: [PATCH v2 6/7] checkout: split into switch-branch and checkout-files Date: Tue, 27 Nov 2018 17:52:10 +0100 Message-Id: <20181127165211.24763-7-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1327.g328c130451.dirty In-Reply-To: <20181127165211.24763-1-pclouds@gmail.com> References: <20181120174554.GA29910@duynguyen.home> <20181127165211.24763-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP "git checkout" doing too many things is a source of confusion for many users (and it even bites old timers sometimes). To rememdy that, the command is now split in two: switch-branch and checkout-files. The switch-branch command is all about switching branches, detaching, DWIM-ing new branch... It does not accept pathspecs and it always requires a ref (in contrast, "git checkout" without arguments works) The checkout-files command on the other hand is all about resetting certain files in worktree, either from the index or from a specific tree. It could accept a tree-ish, but it will never touch HEAD or the ref it points to. The good old "git checkout" command is still here and will be until all (or most of users) are sick of it. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin.h | 2 + builtin/checkout.c | 91 +++++++++++++++++++++++++++++++++++++++------- git.c | 2 + 3 files changed, 82 insertions(+), 13 deletions(-) diff --git a/builtin.h b/builtin.h index 6538932e99..d4a66e5f79 100644 --- a/builtin.h +++ b/builtin.h @@ -138,6 +138,7 @@ extern int cmd_branch(int argc, const char **argv, const char *prefix); extern int cmd_bundle(int argc, const char **argv, const char *prefix); extern int cmd_cat_file(int argc, const char **argv, const char *prefix); extern int cmd_checkout(int argc, const char **argv, const char *prefix); +extern int cmd_checkout_files(int argc, const char **argv, const char *prefix); extern int cmd_checkout_index(int argc, const char **argv, const char *prefix); extern int cmd_check_attr(int argc, const char **argv, const char *prefix); extern int cmd_check_ignore(int argc, const char **argv, const char *prefix); @@ -227,6 +228,7 @@ extern int cmd_show_index(int argc, const char **argv, const char *prefix); extern int cmd_status(int argc, const char **argv, const char *prefix); extern int cmd_stripspace(int argc, const char **argv, const char *prefix); extern int cmd_submodule__helper(int argc, const char **argv, const char *prefix); +extern int cmd_switch_branch(int argc, const char **argv, const char *prefix); extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix); extern int cmd_tag(int argc, const char **argv, const char *prefix); extern int cmd_tar_tree(int argc, const char **argv, const char *prefix); diff --git a/builtin/checkout.c b/builtin/checkout.c index d9dbd2d40d..c09d2da47a 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -33,6 +33,16 @@ static const char * const checkout_usage[] = { NULL, }; +static const char * const switch_branch_usage[] = { + N_("git switch-branch [] "), + NULL, +}; + +static const char * const checkout_files_usage[] = { + N_("git checkout-files [] [] -- ..."), + NULL, +}; + struct checkout_opts { int patch_mode; int quiet; @@ -45,6 +55,8 @@ struct checkout_opts { int ignore_other_worktrees; int show_progress; int dwim_new_local_branch; + int accept_pathspec; + int empty_arg_ok; /* * If new checkout options are added, skip_merge_working_tree @@ -1056,7 +1068,7 @@ static int parse_branchname_arg(int argc, const char **argv, arg = argv[0]; dash_dash_pos = -1; for (i = 0; i < argc; i++) { - if (!strcmp(argv[i], "--")) { + if (opts->accept_pathspec && !strcmp(argv[i], "--")) { dash_dash_pos = i; break; } @@ -1067,6 +1079,8 @@ static int parse_branchname_arg(int argc, const char **argv, has_dash_dash = 1; /* case (3) or (1) */ else if (dash_dash_pos >= 2) die(_("only one reference expected, %d given."), dash_dash_pos); + else if (!opts->accept_pathspec) + has_dash_dash = 1; if (!strcmp(arg, "-")) arg = "@{-1}"; @@ -1291,30 +1305,23 @@ static struct option *add_checkout_path_options(struct checkout_opts *opts, return newopts; } -int cmd_checkout(int argc, const char **argv, const char *prefix) +static int checkout_main(int argc, const char **argv, const char *prefix, + struct checkout_opts *opts, struct option *options, + const char * const usagestr[]) { - struct checkout_opts real_opts; - struct checkout_opts *opts = &real_opts; struct branch_info new_branch_info; int dwim_remotes_matched = 0; - struct option *options = NULL; - memset(opts, 0, sizeof(*opts)); memset(&new_branch_info, 0, sizeof(new_branch_info)); opts->overwrite_ignore = 1; opts->prefix = prefix; opts->show_progress = -1; - opts->dwim_new_local_branch = 1; git_config(git_checkout_config, opts); opts->track = BRANCH_TRACK_UNSPECIFIED; - options = add_common_options(opts, options); - options = add_switch_branch_options(opts, options); - options = add_checkout_path_options(opts, options); - - argc = parse_options(argc, argv, prefix, options, checkout_usage, + argc = parse_options(argc, argv, prefix, options, usagestr, PARSE_OPT_KEEP_DASHDASH); if (opts->show_progress < 0) { @@ -1381,7 +1388,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) &dwim_remotes_matched); argv += n; argc -= n; - } + } else if (!opts->empty_arg_ok) + usage_with_options(usagestr, options); if (argc) { parse_pathspec(&opts->pathspec, 0, @@ -1443,3 +1451,60 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) return checkout_branch(opts, &new_branch_info); } } + +int cmd_checkout(int argc, const char **argv, const char *prefix) +{ + struct checkout_opts opts; + struct option *options = NULL; + int ret; + + memset(&opts, 0, sizeof(opts)); + opts.dwim_new_local_branch = 1; + opts.accept_pathspec = 1; + opts.empty_arg_ok = 1; + + options = add_common_options(&opts, options); + options = add_switch_branch_options(&opts, options); + options = add_checkout_path_options(&opts, options); + + ret = checkout_main(argc, argv, prefix, &opts, + options, checkout_usage); + FREE_AND_NULL(options); + return ret; +} + +int cmd_switch_branch(int argc, const char **argv, const char *prefix) +{ + struct checkout_opts opts; + struct option *options = NULL; + int ret; + + memset(&opts, 0, sizeof(opts)); + opts.dwim_new_local_branch = 1; + + options = add_common_options(&opts, options); + options = add_switch_branch_options(&opts, options); + + ret = checkout_main(argc, argv, prefix, &opts, + options, switch_branch_usage); + FREE_AND_NULL(options); + return ret; +} + +int cmd_checkout_files(int argc, const char **argv, const char *prefix) +{ + struct checkout_opts opts; + struct option *options = NULL; + int ret; + + memset(&opts, 0, sizeof(opts)); + opts.accept_pathspec = 1; + + options = add_common_options(&opts, options); + options = add_checkout_path_options(&opts, options); + + ret = checkout_main(argc, argv, prefix, &opts, + options, checkout_files_usage); + FREE_AND_NULL(options); + return ret; +} diff --git a/git.c b/git.c index 2f604a41ea..3b86ba765c 100644 --- a/git.c +++ b/git.c @@ -457,6 +457,7 @@ static struct cmd_struct commands[] = { { "check-mailmap", cmd_check_mailmap, RUN_SETUP }, { "check-ref-format", cmd_check_ref_format, NO_PARSEOPT }, { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE }, + { "checkout-files", cmd_checkout_files, RUN_SETUP | NEED_WORK_TREE }, { "checkout-index", cmd_checkout_index, RUN_SETUP | NEED_WORK_TREE}, { "cherry", cmd_cherry, RUN_SETUP }, @@ -557,6 +558,7 @@ static struct cmd_struct commands[] = { { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT }, + { "switch-branch", cmd_switch_branch, RUN_SETUP | NEED_WORK_TREE }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, { "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG }, { "unpack-file", cmd_unpack_file, RUN_SETUP | NO_PARSEOPT }, From patchwork Tue Nov 27 16:52:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10700859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D0C211869 for ; Tue, 27 Nov 2018 16:53:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9BDC285B0 for ; Tue, 27 Nov 2018 16:53:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACFF42BD2F; Tue, 27 Nov 2018 16:53:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95D5A287CF for ; Tue, 27 Nov 2018 16:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731613AbeK1DwL (ORCPT ); Tue, 27 Nov 2018 22:52:11 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:45178 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731584AbeK1DwK (ORCPT ); Tue, 27 Nov 2018 22:52:10 -0500 Received: by mail-lj1-f193.google.com with SMTP id s5-v6so20674431ljd.12 for ; Tue, 27 Nov 2018 08:53:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9wtYrwDueT/P6NEPuBMCbkLY85cAWutlZ9KEXhLKIDo=; b=bto5sCvFagRcj3D2ug3V00XVorVKKothDQQqx15FDeQc32agOd5wD1fhz/eJKLJ2ek ome+S7La9WnefUi7gi+n07TmdlySToADm+5NxfDw4tqjo7shbqpZesM9tKE/MWfuO4Fs TEI1M6191Zjfe3ABoQmA77nABOPpjpXuZZgesN4+ZXQKq6fwzclqxv2w7rv/x1mvJsx3 2OU0r8tFa6sdbVtRCZHf6roJ3u7G90cHfkruc2JzRD391FETrgbZxrZXVGWuGjBoVmuh fwMSVuJA3NJXyQf0kPQHrlu5NykKAOzjrfeJ+T9AfYVR+KjNME6k+5jcILtkh++70Xyd LkNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9wtYrwDueT/P6NEPuBMCbkLY85cAWutlZ9KEXhLKIDo=; b=pW40pt06pBfSfTwWMlJvj9KduIJP6C8flY4U+yShZd/U+yi5JBKn30Qk7BISNGaaGT e70ugSjtmJEwPFiCtifICJKGXlMAToMuE/CZzp/HyMBNLtibr4JF+cf6VdaMyaQbtvsd Q4MGU1xuQkkNS4M0h3iQp1vkhut7lqgJjrPLiEpEFT54aOoaiyW2mGqaWk6aGRjqFHzH JADl6vN/UdlxJ8We2uXskSuBodRabzHTkSj0RIMkwK7p0gtmz4KQx9N7zwA17sL6/Ovw YU2JqOal3vzBYZQnF3yf88xOHx791oitZ2/53lMO6JUzccXnT0wGIbslJNpaffsXEchr N1dQ== X-Gm-Message-State: AA+aEWbz4odWDpacLZN8cvZPaPokQqiTeWm2Z0a8lq6w1n6BuIdUa6/k CTTMWDMO2FtWAG3Yi7BdfRA= X-Google-Smtp-Source: AFSGD/WHgnL3VY/EyKyo15TNyusq5ERaXDNR2WVDKS/o4Pc4CgJRHAyUPHrJkWho33lPqO7S9R9h3Q== X-Received: by 2002:a2e:97d7:: with SMTP id m23-v6mr22168899ljj.18.1543337616328; Tue, 27 Nov 2018 08:53:36 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g66sm694016lfe.42.2018.11.27.08.53.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:53:35 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, Stefan Beller , t.gummerer@gmail.com Subject: [PATCH v2 7/7] Suggest other commands instead of "git checkout" Date: Tue, 27 Nov 2018 17:52:11 +0100 Message-Id: <20181127165211.24763-8-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1327.g328c130451.dirty In-Reply-To: <20181127165211.24763-1-pclouds@gmail.com> References: <20181120174554.GA29910@duynguyen.home> <20181127165211.24763-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The assumption made is here - "git checkout" is a horrible monster that should only be touched with a two-meter pole - there are other commands that can achieve the same thing Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation/git-branch.txt | 8 ++-- Documentation/git-check-ref-format.txt | 2 +- Documentation/git-format-patch.txt | 2 +- Documentation/git-merge-base.txt | 2 +- Documentation/git-rebase.txt | 2 +- Documentation/git-remote.txt | 2 +- Documentation/git-rerere.txt | 10 ++--- Documentation/git-reset.txt | 18 ++++----- Documentation/git-revert.txt | 2 +- Documentation/git-stash.txt | 6 +-- Documentation/gitattributes.txt | 2 +- Documentation/gitcli.txt | 4 +- Documentation/gitcore-tutorial.txt | 18 ++++----- Documentation/giteveryday.txt | 24 ++++++------ Documentation/githooks.txt | 5 ++- Documentation/gittutorial-2.txt | 2 +- Documentation/gittutorial.txt | 4 +- Documentation/revisions.txt | 2 +- Documentation/user-manual.txt | 54 +++++++++++++------------- advice.c | 2 +- sha1-name.c | 2 +- wt-status.c | 2 +- 22 files changed, 88 insertions(+), 87 deletions(-) diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index bf5316ffa9..1564df47d2 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -48,7 +48,7 @@ The command's second form creates a new branch head named which points to the current `HEAD`, or if given. Note that this will create the new branch, but it will not switch the -working tree to it; use "git checkout " to switch to the +working tree to it; use "git switch-branch " to switch to the new branch. When a local branch is started off a remote-tracking branch, Git sets up the @@ -194,7 +194,7 @@ This option is only applicable in non-verbose mode. + This behavior is the default when the start point is a remote-tracking branch. Set the branch.autoSetupMerge configuration variable to `false` if you -want `git checkout` and `git branch` to always behave as if `--no-track` +want `git switch-branch` and `git branch` to always behave as if `--no-track` were given. Set it to `always` if you want this behavior when the start-point is either a local or remote-tracking branch. @@ -293,7 +293,7 @@ Start development from a known tag:: $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6 $ cd my2.6 $ git branch my2.6.14 v2.6.14 <1> -$ git checkout my2.6.14 +$ git switch-branch my2.6.14 ------------ + <1> This step and the next one could be combined into a single step with @@ -319,7 +319,7 @@ NOTES ----- If you are creating a branch that you want to checkout immediately, it is -easier to use the git checkout command with its `-b` option to create +easier to use the "git switch-branch" command with its `-b` option to create a branch and check it out with a single command. The options `--contains`, `--no-contains`, `--merged` and `--no-merged` diff --git a/Documentation/git-check-ref-format.txt b/Documentation/git-check-ref-format.txt index d9de992585..38c2169d7a 100644 --- a/Documentation/git-check-ref-format.txt +++ b/Documentation/git-check-ref-format.txt @@ -88,7 +88,7 @@ but it is explicitly forbidden at the beginning of a branch name). When run with `--branch` option in a repository, the input is first expanded for the ``previous checkout syntax'' `@{-n}`. For example, `@{-1}` is a way to refer the last thing that -was checked out using "git checkout" operation. This option should be +was checked out using "git switch-branch" operation. This option should be used by porcelains to accept this syntax anywhere a branch name is expected, so they can act as if you typed the branch name. As an exception note that, the ``previous checkout operation'' might result diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index aba4c5febe..0ceaa1173c 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -416,7 +416,7 @@ One way to test if your MUA is set up correctly is: * Apply it: $ git fetch master:test-apply - $ git checkout test-apply + $ git switch-branch test-apply $ git reset --hard $ git am a.patch diff --git a/Documentation/git-merge-base.txt b/Documentation/git-merge-base.txt index 9f07f4f6ed..1b25e5d530 100644 --- a/Documentation/git-merge-base.txt +++ b/Documentation/git-merge-base.txt @@ -149,7 +149,7 @@ instead. Discussion on fork-point mode ----------------------------- -After working on the `topic` branch created with `git checkout -b +After working on the `topic` branch created with `git switch-branch -b topic origin/master`, the history of remote-tracking branch `origin/master` may have been rewound and rebuilt, leading to a history of this shape: diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 80793bad8d..fe10880633 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -17,7 +17,7 @@ SYNOPSIS DESCRIPTION ----------- If is specified, 'git rebase' will perform an automatic -`git checkout ` before doing anything else. Otherwise +`git switch-branch ` before doing anything else. Otherwise it remains on the current branch. If is not specified, the upstream configured in diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt index 0cad37fb81..044bbdb27c 100644 --- a/Documentation/git-remote.txt +++ b/Documentation/git-remote.txt @@ -230,7 +230,7 @@ $ git branch -r staging/master staging/staging-linus staging/staging-next -$ git checkout -b staging staging/master +$ git switch-branch -b staging staging/master ... ------------ diff --git a/Documentation/git-rerere.txt b/Documentation/git-rerere.txt index df310d2a58..fe9d21b395 100644 --- a/Documentation/git-rerere.txt +++ b/Documentation/git-rerere.txt @@ -91,7 +91,7 @@ For such a test, you need to merge master and topic somehow. One way to do it is to pull master into the topic branch: ------------ - $ git checkout topic + $ git switch-branch topic $ git merge master o---*---o---+ topic @@ -113,10 +113,10 @@ the upstream might have been advanced since the test merge `+`, in which case the final commit graph would look like this: ------------ - $ git checkout topic + $ git switch-branch topic $ git merge master $ ... work on both topic and master branches - $ git checkout master + $ git switch-branch master $ git merge topic o---*---o---+---o---o topic @@ -136,11 +136,11 @@ merges, you could blow away the test merge, and keep building on top of the tip before the test merge: ------------ - $ git checkout topic + $ git switch-branch topic $ git merge master $ git reset --hard HEAD^ ;# rewind the test merge $ ... work on both topic and master branches - $ git checkout master + $ git switch-branch master $ git merge topic o---*---o-------o---o topic diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 2dac95c71a..ca46b4c967 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -149,9 +149,9 @@ See also the --amend option to linkgit:git-commit[1]. Undo a commit, making it a topic branch:: + ------------ -$ git branch topic/wip <1> -$ git reset --hard HEAD~3 <2> -$ git checkout topic/wip <3> +$ git branch topic/wip <1> +$ git reset --hard HEAD~3 <2> +$ git switch-branch topic/wip <3> ------------ + <1> You have made some commits, but realize they were premature @@ -232,13 +232,13 @@ working tree are not in any shape to be committed yet, but you need to get to the other branch for a quick bugfix. + ------------ -$ git checkout feature ;# you were working in "feature" branch and +$ git switch-branch feature ;# you were working in "feature" branch and $ work work work ;# got interrupted $ git commit -a -m "snapshot WIP" <1> -$ git checkout master +$ git switch-branch master $ fix fix fix $ git commit ;# commit with real log -$ git checkout feature +$ git switch-branch feature $ git reset --soft HEAD^ ;# go back to WIP state <2> $ git reset <3> ------------ @@ -279,18 +279,18 @@ reset it while keeping the changes in your working tree. + ------------ $ git tag start -$ git checkout -b branch1 +$ git switch-branch -b branch1 $ edit $ git commit ... <1> $ edit -$ git checkout -b branch2 <2> +$ git switch-branch -b branch2 <2> $ git reset --keep start <3> ------------ + <1> This commits your first edits in branch1. <2> In the ideal world, you could have realized that the earlier commit did not belong to the new topic when you created and switched - to branch2 (i.e. "git checkout -b branch2 start"), but nobody is + to branch2 (i.e. "git switch-branch -b branch2 start"), but nobody is perfect. <3> But you can use "reset --keep" to remove the unwanted commit after you switched to "branch2". diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt index 837707a8fd..e49dbbec83 100644 --- a/Documentation/git-revert.txt +++ b/Documentation/git-revert.txt @@ -26,7 +26,7 @@ effect of some earlier commits (often only a faulty one). If you want to throw away all uncommitted changes in your working directory, you should see linkgit:git-reset[1], particularly the `--hard` option. If you want to extract specific files as they were in another commit, you -should see linkgit:git-checkout[1], specifically the `git checkout +should see linkgit:git-checkout[1], specifically the `git checkout-files -- ` syntax. Take care with these alternatives as both will discard uncommitted changes in your working directory. diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index 7ef8c47911..ea226979b1 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -235,12 +235,12 @@ return to your original branch to make the emergency fix, like this: + ---------------------------------------------------------------- # ... hack hack hack ... -$ git checkout -b my_wip +$ git switch-branch -b my_wip $ git commit -a -m "WIP" -$ git checkout master +$ git switch-branch master $ edit emergency fix $ git commit -a -m "Fix in a hurry" -$ git checkout my_wip +$ git switch-branch my_wip $ git reset --soft HEAD^ # ... continue hacking ... ---------------------------------------------------------------- diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index b8392fc330..df62bd8019 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -112,7 +112,7 @@ Checking-out and checking-in These attributes affect how the contents stored in the repository are copied to the working tree files when commands -such as 'git checkout' and 'git merge' run. They also affect how +such as 'git switch-branch' and 'git merge' run. They also affect how Git stores the contents you prepare in the working tree in the repository upon 'git add' and 'git commit'. diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt index 592e06d839..0ad4869f2c 100644 --- a/Documentation/gitcli.txt +++ b/Documentation/gitcli.txt @@ -47,8 +47,8 @@ disambiguating `--` at appropriate places. things: + -------------------------------- -$ git checkout -- *.c -$ git checkout -- \*.c +$ git checkout-files -- *.c +$ git checkout-files -- \*.c -------------------------------- + The former lets your shell expand the fileglob, and you are asking diff --git a/Documentation/gitcore-tutorial.txt b/Documentation/gitcore-tutorial.txt index e29a9effcc..49a8b5aa52 100644 --- a/Documentation/gitcore-tutorial.txt +++ b/Documentation/gitcore-tutorial.txt @@ -741,7 +741,7 @@ used earlier, and create a branch in it. You do that by simply just saying that you want to check out a new branch: ------------ -$ git checkout -b mybranch +$ git branch mybranch ------------ will create a new branch based at the current `HEAD` position, and switch @@ -755,7 +755,7 @@ just telling 'git checkout' what the base of the checkout would be. In other words, if you have an earlier tag or branch, you'd just do ------------ -$ git checkout -b mybranch earlier-commit +$ git switch-branch -b mybranch earlier-commit ------------ and it would create the new branch `mybranch` at the earlier commit, @@ -765,7 +765,7 @@ and check out the state at that time. You can always just jump back to your original `master` branch by doing ------------ -$ git checkout master +$ git switch-branch master ------------ (or any other branch-name, for that matter) and if you forget which @@ -794,7 +794,7 @@ $ git branch [startingpoint] which will simply _create_ the branch, but will not do anything further. You can then later -- once you decide that you want to actually develop -on that branch -- switch to that branch with a regular 'git checkout' +on that branch -- switch to that branch with a regular 'git switch-branch with the branchname as the argument. @@ -808,7 +808,7 @@ being the same as the original `master` branch, let's make sure we're in that branch, and do some work there. ------------------------------------------------ -$ git checkout mybranch +$ git switch-branch mybranch $ echo "Work, work, work" >>hello $ git commit -m "Some work." -i hello ------------------------------------------------ @@ -825,7 +825,7 @@ does some work in the original branch, and simulate that by going back to the master branch, and editing the same file differently there: ------------ -$ git checkout master +$ git switch-branch master ------------ Here, take a moment to look at the contents of `hello`, and notice how they @@ -958,7 +958,7 @@ to the `master` branch. Let's go back to `mybranch`, and run 'git merge' to get the "upstream changes" back to your branch. ------------ -$ git checkout mybranch +$ git switch-branch mybranch $ git merge -m "Merge upstream changes." master ------------ @@ -1133,9 +1133,9 @@ Remember, before running 'git merge', our `master` head was at work." commit. ------------ -$ git checkout mybranch +$ git switch-branch mybranch $ git reset --hard master^2 -$ git checkout master +$ git switch-branch master $ git reset --hard master^ ------------ diff --git a/Documentation/giteveryday.txt b/Documentation/giteveryday.txt index 9f2528fc8c..861b2bb616 100644 --- a/Documentation/giteveryday.txt +++ b/Documentation/giteveryday.txt @@ -80,9 +80,9 @@ $ git tag v2.43 <2> Create a topic branch and develop.:: + ------------ -$ git checkout -b alsa-audio <1> +$ git branch alsa-audio <1> $ edit/compile/test -$ git checkout -- curses/ux_audio_oss.c <2> +$ git checkout-files -- curses/ux_audio_oss.c <2> $ git add curses/ux_audio_alsa.c <3> $ edit/compile/test $ git diff HEAD <4> @@ -90,7 +90,7 @@ $ git commit -a -s <5> $ edit/compile/test $ git diff HEAD^ <6> $ git commit -a --amend <7> -$ git checkout master <8> +$ git switch-branch master <8> $ git merge alsa-audio <9> $ git log --since='3 days ago' <10> $ git log v2.43.. curses/ <11> @@ -148,11 +148,11 @@ Clone the upstream and work on it. Feed changes to upstream.:: ------------ $ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6 $ cd my2.6 -$ git checkout -b mine master <1> +$ git switch-branch -b mine master <1> $ edit/compile/test; git commit -a -s <2> $ git format-patch master <3> $ git send-email --to="person " 00*.patch <4> -$ git checkout master <5> +$ git switch-branch master <5> $ git pull <6> $ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 <7> $ git ls-remote --heads http://git.kernel.org/.../jgarzik/libata-dev.git <8> @@ -194,7 +194,7 @@ satellite$ edit/compile/test/commit satellite$ git push origin <4> mothership$ cd frotz -mothership$ git checkout master +mothership$ git switch-branch master mothership$ git merge satellite/master <5> ------------ + @@ -216,7 +216,7 @@ machine into the master branch. Branch off of a specific tag.:: + ------------ -$ git checkout -b private2.6.14 v2.6.14 <1> +$ git switch-branch -b private2.6.14 v2.6.14 <1> $ edit/compile/test; git commit -a $ git checkout master $ git cherry-pick v2.6.14..private2.6.14 <2> @@ -274,14 +274,14 @@ $ mailx <3> & s 2 3 4 5 ./+to-apply & s 7 8 ./+hold-linus & q -$ git checkout -b topic/one master +$ git switch-branch -b topic/one master $ git am -3 -i -s ./+to-apply <4> $ compile/test -$ git checkout -b hold/linus && git am -3 -i -s ./+hold-linus <5> -$ git checkout topic/one && git rebase master <6> -$ git checkout pu && git reset --hard next <7> +$ git switch-branch -b hold/linus && git am -3 -i -s ./+hold-linus <5> +$ git switch-branch topic/one && git rebase master <6> +$ git switch-branch pu && git reset --hard next <7> $ git merge topic/one topic/two && git merge hold/linus <8> -$ git checkout maint +$ git switch-branch maint $ git cherry-pick master~4 <9> $ compile/test $ git tag -s -m "GIT 0.99.9x" v0.99.9x <10> diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 959044347e..3939ec774a 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -166,7 +166,7 @@ worktree. The hook is given three parameters: the ref of the previous HEAD, the ref of the new HEAD (which may or may not have changed), and a flag indicating whether the checkout was a branch checkout (changing branches, flag=1) or a file checkout (retrieving a file from the index, flag=0). -This hook cannot affect the outcome of `git checkout`. +This hook cannot affect the outcome of `git switch-branch` or `git checkout`. It is also run after linkgit:git-clone[1], unless the `--no-checkout` (`-n`) option is used. The first parameter given to the hook is the null-ref, the second the @@ -402,7 +402,8 @@ exit with a zero status. For example, the hook can simply run `git read-tree -u -m HEAD "$1"` in order to emulate `git fetch` that is run in the reverse direction with `git push`, as the two-tree form of `git read-tree -u -m` is -essentially the same as `git checkout` that switches branches while +essentially the same as `git switch-branch` or `git checkout` +that switches branches while keeping the local changes in the working tree that do not interfere with the difference between the branches. diff --git a/Documentation/gittutorial-2.txt b/Documentation/gittutorial-2.txt index e0976f6017..125213d951 100644 --- a/Documentation/gittutorial-2.txt +++ b/Documentation/gittutorial-2.txt @@ -376,7 +376,7 @@ Changes to be committed: Changes not staged for commit: (use "git add ..." to update what will be committed) - (use "git checkout -- ..." to discard changes in working directory) + (use "git checkout-files -- ..." to discard changes in working directory) modified: file.txt diff --git a/Documentation/gittutorial.txt b/Documentation/gittutorial.txt index 242de31cb6..396e55c191 100644 --- a/Documentation/gittutorial.txt +++ b/Documentation/gittutorial.txt @@ -207,7 +207,7 @@ automatically. The asterisk marks the branch you are currently on; type ------------------------------------------------ -$ git checkout experimental +$ git switch-branch experimental ------------------------------------------------ to switch to the experimental branch. Now edit a file, commit the @@ -216,7 +216,7 @@ change, and switch back to the master branch: ------------------------------------------------ (edit file) $ git commit -a -$ git checkout master +$ git switch-branch master ------------------------------------------------ Check that the change you made is no longer visible, since it was diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index 72daa20e76..f55502cd50 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -115,7 +115,7 @@ Here's an example to make it more clear: ------------------------------ $ git config push.default current $ git config remote.pushdefault myfork -$ git checkout -b mybranch origin/master +$ git switch-branch -b mybranch origin/master $ git rev-parse --symbolic-full-name @{upstream} refs/remotes/origin/master diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index eff7890274..56397e93d4 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -125,7 +125,7 @@ Create a new branch head pointing to one of these versions and check it out using linkgit:git-checkout[1]: ------------------------------------------------ -$ git checkout -b new v2.6.13 +$ git switch-branch -b new v2.6.13 ------------------------------------------------ The working directory then reflects the contents that the project had @@ -282,10 +282,10 @@ a summary of the commands: this command will fail with a warning. `git branch -D `:: delete the branch `` irrespective of its merged status. -`git checkout `:: +`git switch-branch `:: make the current branch ``, updating the working directory to reflect the version referenced by ``. -`git checkout -b `:: +`git switch-branch -b `:: create a new branch `` referencing ``, and check it out. @@ -302,12 +302,12 @@ ref: refs/heads/master Examining an old version without creating a new branch ------------------------------------------------------ -The `git checkout` command normally expects a branch head, but will also +The `git switch-branch` command normally expects a branch head, but will also accept an arbitrary commit; for example, you can check out the commit referenced by a tag: ------------------------------------------------ -$ git checkout v2.6.17 +$ git switch-branch v2.6.17 Note: checking out 'v2.6.17'. You are in 'detached HEAD' state. You can look around, make experimental @@ -317,7 +317,7 @@ state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: - git checkout -b new_branch_name + git switch-branch -b new_branch_name HEAD is now at 427abfa Linux v2.6.17 ------------------------------------------------ @@ -373,7 +373,7 @@ You might want to build on one of these remote-tracking branches on a branch of your own, just as you would for a tag: ------------------------------------------------ -$ git checkout -b my-todo-copy origin/todo +$ git switch-branch -b my-todo-copy origin/todo ------------------------------------------------ You can also check out `origin/todo` directly to examine it or @@ -1523,12 +1523,12 @@ Checking out an old version of a file In the process of undoing a previous bad change, you may find it useful to check out an older version of a particular file using -linkgit:git-checkout[1]. We've used `git checkout` before to switch +linkgit:git-checkout[1]. We've used `git switch-branch` before to switch branches, but it has quite different behavior if it is given a path name: the command ------------------------------------------------- -$ git checkout HEAD^ path/to/file +$ git checkout-files HEAD^ path/to/file ------------------------------------------------- replaces path/to/file by the contents it had in the commit HEAD^, and @@ -2211,8 +2211,8 @@ $ git branch --track release origin/master These can be easily kept up to date using linkgit:git-pull[1]. ------------------------------------------------- -$ git checkout test && git pull -$ git checkout release && git pull +$ git switch-branch test && git pull +$ git switch-branch release && git pull ------------------------------------------------- Important note! If you have any local changes in these branches, then @@ -2264,7 +2264,7 @@ tested changes 2) help future bug hunters that use `git bisect` to find problems ------------------------------------------------- -$ git checkout -b speed-up-spinlocks v2.6.35 +$ git switch-branch -b speed-up-spinlocks v2.6.35 ------------------------------------------------- Now you apply the patch(es), run some tests, and commit the change(s). If @@ -2279,7 +2279,7 @@ When you are happy with the state of this change, you can merge it into the "test" branch in preparation to make it public: ------------------------------------------------- -$ git checkout test && git merge speed-up-spinlocks +$ git switch-branch test && git merge speed-up-spinlocks ------------------------------------------------- It is unlikely that you would have any conflicts here ... but you might if you @@ -2291,7 +2291,7 @@ see the value of keeping each patch (or patch series) in its own branch. It means that the patches can be moved into the `release` tree in any order. ------------------------------------------------- -$ git checkout release && git merge speed-up-spinlocks +$ git switch-branch release && git merge speed-up-spinlocks ------------------------------------------------- After a while, you will have a number of branches, and despite the @@ -2358,7 +2358,7 @@ Here are some of the scripts that simplify all this even further. case "$1" in test|release) - git checkout $1 && git pull . origin + git switch-branch $1 && git pull . origin ;; origin) before=$(git rev-parse refs/remotes/origin/master) @@ -2400,7 +2400,7 @@ test|release) echo $1 already merged into $2 1>&2 exit 1 fi - git checkout $2 && git pull . $1 + git switch-branch $2 && git pull . $1 ;; *) usage @@ -2512,7 +2512,7 @@ Suppose that you create a branch `mywork` on a remote-tracking branch `origin`, and create some commits on top of it: ------------------------------------------------- -$ git checkout -b mywork origin +$ git switch-branch -b mywork origin $ vi file.txt $ git commit $ vi otherfile.txt @@ -2552,7 +2552,7 @@ commits without any merges, you may instead choose to use linkgit:git-rebase[1]: ------------------------------------------------- -$ git checkout mywork +$ git switch-branch mywork $ git rebase origin ------------------------------------------------- @@ -3668,13 +3668,13 @@ change within the submodule, and then update the superproject to reference the new commit: ------------------------------------------------- -$ git checkout master +$ git switch-branch master ------------------------------------------------- or ------------------------------------------------- -$ git checkout -b fix-up +$ git switch-branch -b fix-up ------------------------------------------------- then @@ -4194,7 +4194,7 @@ start. A good place to start is with the contents of the initial commit, with: ---------------------------------------------------- -$ git checkout e83c5163 +$ git switch-branch e83c5163 ---------------------------------------------------- The initial revision lays the foundation for almost everything Git has @@ -4437,10 +4437,10 @@ Managing branches ----------------- ----------------------------------------------- -$ git branch # list all local branches in this repo -$ git checkout test # switch working directory to branch "test" -$ git branch new # create branch "new" starting at current HEAD -$ git branch -d new # delete branch "new" +$ git branch # list all local branches in this repo +$ git switch-branch test # switch working directory to branch "test" +$ git branch new # create branch "new" starting at current HEAD +$ git branch -d new # delete branch "new" ----------------------------------------------- Instead of basing a new branch on current HEAD (the default), use: @@ -4456,7 +4456,7 @@ $ git branch new test~10 # ten commits before tip of branch "test" Create and switch to a new branch at the same time: ----------------------------------------------- -$ git checkout -b new v2.6.15 +$ git switch-branch -b new v2.6.15 ----------------------------------------------- Update and examine branches from the repository you cloned from: @@ -4467,7 +4467,7 @@ $ git branch -r # list origin/master origin/next ... -$ git checkout -b masterwork origin/master +$ git switch-branch -b masterwork origin/master ----------------------------------------------- Fetch a branch from a different repository, and give it a new diff --git a/advice.c b/advice.c index 5f35656409..1befdb2163 100644 --- a/advice.c +++ b/advice.c @@ -195,7 +195,7 @@ void detach_advice(const char *new_name) "state without impacting any branches by performing another checkout.\n\n" "If you want to create a new branch to retain commits you create, you may\n" "do so (now or later) by using -b with the checkout command again. Example:\n\n" - " git checkout -b \n\n"); + " git branch \n\n"); fprintf(stderr, fmt, new_name); } diff --git a/sha1-name.c b/sha1-name.c index faa60f69e3..4e4e14a45c 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -771,7 +771,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid, "because it will be ignored when you just specify 40-hex. These refs\n" "may be created by mistake. For example,\n" "\n" - " git checkout -b $br $(git rev-parse ...)\n" + " git switch-branch -b $br $(git rev-parse ...)\n" "\n" "where \"$br\" is somehow empty and a 40-hex ref is created. Please\n" "examine these refs and maybe delete them. Turn this message off by\n" diff --git a/wt-status.c b/wt-status.c index a24711374c..6266683926 100644 --- a/wt-status.c +++ b/wt-status.c @@ -224,7 +224,7 @@ static void wt_longstatus_print_dirty_header(struct wt_status *s, status_printf_ln(s, c, _(" (use \"git add ...\" to update what will be committed)")); else status_printf_ln(s, c, _(" (use \"git add/rm ...\" to update what will be committed)")); - status_printf_ln(s, c, _(" (use \"git checkout -- ...\" to discard changes in working directory)")); + status_printf_ln(s, c, _(" (use \"git checkout-files ...\" to discard changes in working directory)")); if (has_dirty_submodules) status_printf_ln(s, c, _(" (commit or discard the untracked or modified content in submodules)")); status_printf_ln(s, c, "%s", "");