From patchwork Wed Jan 30 09:48:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10788091 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 A1D8417E9 for ; Wed, 30 Jan 2019 09:49:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E56C2DF2D for ; Wed, 30 Jan 2019 09:49:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82EC82DFE9; Wed, 30 Jan 2019 09:49:37 +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 156642DF2D for ; Wed, 30 Jan 2019 09:49:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730525AbfA3Jtg (ORCPT ); Wed, 30 Jan 2019 04:49:36 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42590 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726972AbfA3Jtf (ORCPT ); Wed, 30 Jan 2019 04:49:35 -0500 Received: by mail-pf1-f196.google.com with SMTP id 64so11163921pfr.9 for ; Wed, 30 Jan 2019 01:49: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=m8JBLntTWOBkAbkZhV5h0lAVUZl4Ao1ffYaYROjX5Qw=; b=UrrbsSysxjsMGlkUCU2qsIRJ5o22yokv56aPmDOnUOUXztWwKEfDfjTGtNv5/QTRQC t96XGjmnaUrb2rNwqPUtex31Tp40lj6W/2ByOYDSw3ilPDPc2feGqJUSueZbWsBJ2KBq b3rxIUyWpbhyGNGqzMn1GH66NTzKLGocs/qnfClwhK+6UX3UmCvMxJvLm1jxp2hjAQi9 wZthlKo6SVyCG5r8X+lXWQp/m3nS5vApqvot8Vsc6InEpncU1suJ6v2tp47hbOhuRdTJ 5Oj2QtVpKVsMoi4dRXUpH6YCjexcBhxthN9BmjoWjWYtvyVNOqwUITj8j0bKwjS9/QJv LuAA== 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=m8JBLntTWOBkAbkZhV5h0lAVUZl4Ao1ffYaYROjX5Qw=; b=dMMDoBEYbPgm1SiWi8kdvN3eVc7kFYypmCPLf1IdUYAFBQkwZkQuVaKpfO103tKOI3 ow2Lfiz8+SQYnWbT4H/4FIShQt6QgZ5uNJ/RTfF0YEkfamDtBJnygUIOy8sAe/OqIqJW ci/ClYkF4FD2fqqcVxq8iYbJm3nji0LCSBT7m+JUC/IJILwedCPF8a2XHi4XZcPVkSNe b/g9Txn3qSa5oUCeguaeKM7BotIebGGHVGnlHFu+sD1ziF+h+/INcdPAwQWcEQPE2p7B jwBkAj/ueabtEhUI9Xa3AR7P18/duf3AonOuT0iTY1DDmrL8qIop+lmJzB8w6xDuwHXk SzSw== X-Gm-Message-State: AJcUukfDGHqJY7qeSH6dldh0BgCAgWdXPorkna1PZDBv9mVveRdm7si2 r3pQ5f9ak/JxP3nPHwGS8L8dq4V/ X-Google-Smtp-Source: ALg8bN6I2wche09acGMZH2lv73WebnkAXSG1kHcc9J1/AITg+pQGONTFguAcUynXtZbXivsUQlg4hw== X-Received: by 2002:a65:4b82:: with SMTP id t2mr26999517pgq.189.1548841774652; Wed, 30 Jan 2019 01:49:34 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id s190sm1632943pfb.103.2019.01.30.01.49.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 01:49:34 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Wed, 30 Jan 2019 16:49:30 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 12/19] switch: reject "do nothing" case Date: Wed, 30 Jan 2019 16:48:24 +0700 Message-Id: <20190130094831.10420-13-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.682.gd5861c6d90 In-Reply-To: <20190130094831.10420-1-pclouds@gmail.com> References: <20190130094831.10420-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" can be executed without any arguments. What it does is not exactly great: it switches from HEAD to HEAD and shows worktree modification as a side effect. Make switch reject this case. Just use "git status" if you want that side effect. For switch, you have to either - really switch a branch - (explicitly) detach from the current branch - create a new branch Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/builtin/checkout.c b/builtin/checkout.c index 7906e07352..9a58fccd71 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -53,6 +53,7 @@ struct checkout_opts { int overlay_mode; int no_dwim_new_local_branch; int accept_pathspec; + int switch_branch_doing_nothing_is_ok; /* * If new checkout options are added, skip_merge_working_tree @@ -1319,6 +1320,12 @@ 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) + die(_("nothing to do")); + if (new_branch_info->path && !opts->force_detach && !opts->new_branch && !opts->ignore_other_worktrees) { int flag; @@ -1572,6 +1579,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) memset(&opts, 0, sizeof(opts)); opts.no_dwim_new_local_branch = 0; + opts.switch_branch_doing_nothing_is_ok = 1; opts.accept_pathspec = 1; options = parse_options_dup(checkout_options); @@ -1601,6 +1609,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix) memset(&opts, 0, sizeof(opts)); opts.no_dwim_new_local_branch = 0; opts.accept_pathspec = 0; + opts.switch_branch_doing_nothing_is_ok = 0; options = parse_options_dup(switch_options); options = add_common_options(&opts, options);