From patchwork Thu Jun 20 09:55:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 11006329 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 D7D4176 for ; Thu, 20 Jun 2019 09:55:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8EDD27F82 for ; Thu, 20 Jun 2019 09:55:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA8EF2832B; Thu, 20 Jun 2019 09:55: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 7106327F82 for ; Thu, 20 Jun 2019 09:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726404AbfFTJzg (ORCPT ); Thu, 20 Jun 2019 05:55:36 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36335 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726234AbfFTJzg (ORCPT ); Thu, 20 Jun 2019 05:55:36 -0400 Received: by mail-pf1-f193.google.com with SMTP id r7so1380178pfl.3 for ; Thu, 20 Jun 2019 02:55:36 -0700 (PDT) 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=1gxcI9NLNmLhk54Ses/+egBIjoZcrFCzeseEKkzO4pM=; b=RpMVJmO/rOevlcXS+2xCiPvkpxWod+5TFgColWNxw3cvwLSM3tuqCDKSshr1TzRDLl Z3riGVVCQgphbDk+PVAXnBfWMmKlcOn3p2TG7DhMckHE99XAXknLpof0NfH+q84B7rxm 5lxLbGCZfFRC/9TkV99hVSWBAUu/eE3cxQ1K6pa1n9pwCRmpUtUrAj+qULVrYgd/Hpfp pG1w66zs5t47e29ABqKz39QFwZT16zxelAuPwsSan4fi+Mp9NAgXeuMBwQ0cycEzMM2k TajnnVKIxOD5gxmmooYEZU0TQQLwQenL0/pLj8LtPUEgh8sT7IlXMMXFU+kqnQ40T/Cu j+EQ== 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=1gxcI9NLNmLhk54Ses/+egBIjoZcrFCzeseEKkzO4pM=; b=WQlTqYLF4oTM/grt+lzItoCUh87D+0ePunS/qQ4r3//EzUzGqKGu5x7KsjQkvC/thM tsxe5dz4v37OkCkcZeuO6YzD0TvM8Hy2aXNRrZeKKSLN0cZ45SMEtsF+FJw7q9gUbus4 S2uP9d0U9g2N+wSHhsYNDI5jfSXnBC9VbkZMXSoCmAFuFaMMZiKuMYa8GZerh+Vgtw3b ro9V16OvMSzX5joG2/OWt8VsSYvflGqnA3WEX+C/FpfF7ywlz0mn4+8svHDgCzlO0/lS E2rluYAljlsk7q0zwIDza0OcDXo3jMjyLILRSt26TGKNxc2WzylFm/2cZSNCtk6SwoYS wrRQ== X-Gm-Message-State: APjAAAVc1Hq/EPoq196nnw1rIHJ4Dy4n+78qtIProV3Kp4AilO1LhXmo R/9tHELx6lN1YjwSm8sVcXAY7RX/ X-Google-Smtp-Source: APXvYqznvbHUgWzkOv5r7c5dmPGkmEY1JG+j8hpdZ8GVTtnD9pa0b0CVGinomTu1FEPdye529AdmdQ== X-Received: by 2002:a63:6946:: with SMTP id e67mr2683617pgc.15.1561024534022; Thu, 20 Jun 2019 02:55:34 -0700 (PDT) Received: from ash ([115.76.181.38]) by smtp.gmail.com with ESMTPSA id t26sm19114266pgu.43.2019.06.20.02.55.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 02:55:32 -0700 (PDT) Received: by ash (sSMTP sendmail emulation); Thu, 20 Jun 2019 16:55:28 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 1/4] t2027: use test_must_be_empty Date: Thu, 20 Jun 2019 16:55:20 +0700 Message-Id: <20190620095523.10003-2-pclouds@gmail.com> X-Mailer: git-send-email 2.22.0.rc0.322.g2b0371e29a In-Reply-To: <20190620095523.10003-1-pclouds@gmail.com> References: <20190620095523.10003-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 --- t/t2070-restore.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/t/t2070-restore.sh b/t/t2070-restore.sh index 73ea13ede9..2650df1966 100755 --- a/t/t2070-restore.sh +++ b/t/t2070-restore.sh @@ -90,9 +90,8 @@ test_expect_success 'restore --ignore-unmerged ignores unmerged entries' ' git restore --ignore-unmerged --quiet . >output 2>&1 && git diff common >diff-output && - : >empty && - test_cmp empty output && - test_cmp empty diff-output + test_must_be_empty output && + test_must_be_empty diff-output ) ' From patchwork Thu Jun 20 09:55:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 11006331 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 C33EB76 for ; Thu, 20 Jun 2019 09:55:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B523527F82 for ; Thu, 20 Jun 2019 09:55:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A99D22832B; Thu, 20 Jun 2019 09:55: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 5287827F82 for ; Thu, 20 Jun 2019 09:55:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726491AbfFTJzj (ORCPT ); Thu, 20 Jun 2019 05:55:39 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38476 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726234AbfFTJzj (ORCPT ); Thu, 20 Jun 2019 05:55:39 -0400 Received: by mail-pf1-f194.google.com with SMTP id a186so1371574pfa.5 for ; Thu, 20 Jun 2019 02:55:39 -0700 (PDT) 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=ipfBxGnjPJNpJXelyM6Q/qLGCyUDjEvkfaB5DkDYjJ8=; b=BHpINkymTWHbObbV0rExcKngxxF8JP348ApXV/izQz/cY28WVyJSiJw5Gq1HEc5zMH t4BbMtY/AiFn0GagEKfE+9MfCNSftWTch625YXvxNilkyQuF8fd8Cq5Zcx7Cvr5+gANE cmLAoPwtffPwTlLHxv+YLwRYJnSabpYzSGoyYiFw8t2GWO+mz8dpD5XXSOy6LdDBYF3z 0QfMUT8kNwCl3dUwGzvFwPTOpilS2fayDM+8O7FFFdkKgqprSTcek4R5EgGIIMTilYyk gJQQ+4BAri0qWTcIpM6HYxVjaZpqteVJ9tpz4dvbFwVocwbAQ471ZjO4ecaelKipRy14 4IHg== 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=ipfBxGnjPJNpJXelyM6Q/qLGCyUDjEvkfaB5DkDYjJ8=; b=R2SwX1a+KgDU07+6kHvgJP8wfLgfv6sH3y4l9ACdZdR60LWobZv40w2XFmnTWqQUpX 4Aaexk1i5y+WSWjGkmd8SDOfy50i9vs7++1f+CVW+BVh2VWmYDKL1nat5B6O4WMr8c7D 6yt887URdbOapSRTy8TSfZ+D//I/8gVH4N+lBv1B6ipRFUL2aNFhFmtCFia+q11UJtc8 2sU48UbR8qM41o5PM1gtodDoF+bJ+BkV1MHX62zmp0wTDr1Bz7Xlw198UPyaKto+EG77 N3xg97BhDQ7x6WXu15wAG97u9cg5pTOpx5xYCipcpjAChvP5L5mkHt7ZGzITWwGLdyyu Xj6w== X-Gm-Message-State: APjAAAV9J+I5KxlD68WRLMkd8G+8zmBNcXUbI4iAtbj10PYUOnUFWfe6 qy1oQsC7EzjPFvwE/iXxHGvso+qY X-Google-Smtp-Source: APXvYqxMbdi1oQccz+jKRpYTom+m9Ox3pIHfe/viyFRGN1L6At4VdRL7DYXXgWmDE90EJEpelXTPOg== X-Received: by 2002:a17:90a:fa18:: with SMTP id cm24mr2157060pjb.120.1561024538543; Thu, 20 Jun 2019 02:55:38 -0700 (PDT) Received: from ash ([115.76.181.38]) by smtp.gmail.com with ESMTPSA id b135sm20716050pfb.44.2019.06.20.02.55.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 02:55:38 -0700 (PDT) Received: by ash (sSMTP sendmail emulation); Thu, 20 Jun 2019 16:55:34 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 2/4] switch: allow to switch in the middle of bisect Date: Thu, 20 Jun 2019 16:55:21 +0700 Message-Id: <20190620095523.10003-3-pclouds@gmail.com> X-Mailer: git-send-email 2.22.0.rc0.322.g2b0371e29a In-Reply-To: <20190620095523.10003-1-pclouds@gmail.com> References: <20190620095523.10003-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 In c45f0f525d (switch: reject if some operation is in progress, 2019-03-29), a check is added to prevent switching when some operation is in progress. The reason is it's often not safe to do so. This is true for merge, am, rebase, cherry-pick and revert, but not so much for bisect because bisecting is basically jumping/switching between a bunch of commits to pin point the first bad one. git-bisect suggests the next commit to test, but it's not wrong for the user to test a different commit because git-bisect cannot have the knowledge to know better. For this reason, allow to switch when bisecting (*). I considered if we should still prevent switching by default and allow it with --ignore-in-progress. But I don't think the prevention really adds anything much. If the user switches away by mistake, since we print the previous HEAD value, even if they don't know about the "-" shortcut, switching back is still possible. The warning will be printed on every switch while bisect is still ongoing, not the first time you switch away from bisect's suggested commit, so it could become a bit annoying. (*) of course when it's safe to do so, i.e. no loss of local changes and stuff. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index bed79ae595..f884d27f1f 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1326,9 +1326,7 @@ static void die_if_some_operation_in_progress(void) "Consider \"git revert --quit\" " "or \"git worktree add\".")); if (state.bisect_in_progress) - die(_("cannot switch branch while bisecting\n" - "Consider \"git bisect reset HEAD\" " - "or \"git worktree add\".")); + warning(_("you are switching branch while bisecting")); } static int checkout_branch(struct checkout_opts *opts, From patchwork Thu Jun 20 09:55:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 11006333 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 D944A112C for ; Thu, 20 Jun 2019 09:55:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB66A27F82 for ; Thu, 20 Jun 2019 09:55:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEF3B2848B; Thu, 20 Jun 2019 09:55: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 75E7C27F82 for ; Thu, 20 Jun 2019 09:55:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726539AbfFTJzn (ORCPT ); Thu, 20 Jun 2019 05:55:43 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35147 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726234AbfFTJzn (ORCPT ); Thu, 20 Jun 2019 05:55:43 -0400 Received: by mail-pf1-f194.google.com with SMTP id d126so1382144pfd.2 for ; Thu, 20 Jun 2019 02:55:43 -0700 (PDT) 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=z1yrcLjzKtHQk9feIb+pcN1vEvD4BtiJjjmN3UHf5Do=; b=sGcphc2f1Syb+rDBaOK/KOYW/x+/MRAgalB5+59jxLXkojJhBlrGd33PGFcOmjTefk MQD3k9XU9Jh0kDrxbCunBFzIZEaUAM1/sqGbXTe1NEqNX6fTaHCT0qOHXo+jiMRQKmZl IvUrpqciQT4TBZ5+DiH7fn8EXb2BGwFABI5jCSwVOliJi6AWT6+viEuOPgc54jvR2OLw niZdesl2eby2dnR47uhmmUS50/0IBYXW5Hkx8XNLryetsgGbO4vVpGA/9OKefMkSLUWF SUukkDE8zgrWCAU++cQbGED24lcRFinPPQaEizkUPN84VmF7MeChqwQNhSJfF+dCOYzg VC7g== 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=z1yrcLjzKtHQk9feIb+pcN1vEvD4BtiJjjmN3UHf5Do=; b=jyQBuwg04k9+iCGujqvjLTUUru9hW29xNFSLgl/JjJ1O8BNLUmI/My0GcLBwg8rwA5 BK4A3yufMlNEZe8BeI4KnVKrs9fU4reULx/5IvAdcWwTZFS1qib0AeJUsJCSfwngJlUp 8a6BfarwM0Ekj8MnWnPifkd5PdQ3VP+yJM3+tADTWzNoowa+VnQCyJc1heYDqH03ss7i 0s/sbGhjQ+Dm11FLGUo2QHTwfqlB0dFyXnVPSp3x4WT3WlMz9YLyUU9wFO3k+2w/wGJJ E/BCTlT8I6vF1H5rAt3THJ2JEr9vbQGV8NNHSJz27wG2zQgaFUBnlXyfF4ugaz2Wp3Kz fRIw== X-Gm-Message-State: APjAAAWi23fteuqNO1D4D11noEEj7a0tZIxk5Eqh8cXqj921ADzrusnG aYzhShGYYE2ZqZD7HfYvNEyTugtk X-Google-Smtp-Source: APXvYqyqT+8Gxil7skScRA1z2ONkATqKTFVSmh/XQ6WRcaKCF1CseKFpFSH10169xbuVyGUPvHXZaA== X-Received: by 2002:a17:90a:af8e:: with SMTP id w14mr2229000pjq.89.1561024542654; Thu, 20 Jun 2019 02:55:42 -0700 (PDT) Received: from ash ([115.76.181.38]) by smtp.gmail.com with ESMTPSA id l194sm21179758pga.57.2019.06.20.02.55.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 02:55:42 -0700 (PDT) Received: by ash (sSMTP sendmail emulation); Thu, 20 Jun 2019 16:55:38 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 3/4] completion: disable dwim on "git switch -d" Date: Thu, 20 Jun 2019 16:55:22 +0700 Message-Id: <20190620095523.10003-4-pclouds@gmail.com> X-Mailer: git-send-email 2.22.0.rc0.322.g2b0371e29a In-Reply-To: <20190620095523.10003-1-pclouds@gmail.com> References: <20190620095523.10003-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 Even though dwim is enabled by default, it will never be done when --detached is specified. If you force "-d --guess" you will get an error because --guess then implies -c which cannot be used with -d. So we can disable dwim in "switch -d". It makes the completion list in this case a bit shorter. Signed-off-by: Nguyễn Thái Ngọc Duy --- contrib/completion/git-completion.bash | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 58d18d41a2..656e49710e 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2183,6 +2183,10 @@ _git_switch () fi if [ -z "$(__git_find_on_cmdline "-d --detach")" ]; then only_local_ref=y + else + # --guess --detach is invalid combination, no + # dwim will be done when --detach is specified + track_opt= fi if [ $only_local_ref = y -a -z "$track_opt" ]; then __gitcomp_direct "$(__git_heads "" "$cur" " ")" From patchwork Thu Jun 20 09:55:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 11006335 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 9AFC476 for ; Thu, 20 Jun 2019 09:55:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BE3B27F82 for ; Thu, 20 Jun 2019 09:55:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FE172832B; Thu, 20 Jun 2019 09:55:49 +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 DE54F27F82 for ; Thu, 20 Jun 2019 09:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726679AbfFTJzs (ORCPT ); Thu, 20 Jun 2019 05:55:48 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39297 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726082AbfFTJzr (ORCPT ); Thu, 20 Jun 2019 05:55:47 -0400 Received: by mail-pg1-f193.google.com with SMTP id 196so1310433pgc.6 for ; Thu, 20 Jun 2019 02:55:47 -0700 (PDT) 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=vu3zC9pM2UbeuPAtGA6ONAVY/TNyoLTb1Mat++/dTkU=; b=EELIP1NOzbs65QtjS2YBXCQUN2fehMoohbfEpmd7WW62WfOVnSfBTlrM5ZgVRe0xFu OSRNweNgtHSiFkkSl6Zh7TNXeHkAUw2PtUfP+Dwm+eY7nddP/s8XwUT7OQAVyqoPY+rG Nkkv3C/lE7n0/U3fMj6Nk4mW04vqtEp7aIlD7Nlh30EECZfTTjRMWyXxEJIyyVahIPxk MDyd8p9zJ4uthR6EmH6VN9ts1BlPOQSLRBOMybL0QVz/GFTtVRzLf0NF5ajNpC98jN9D H86gGiECvmwxARIcfqoeTTpAAnTJPySlpyrUbdgbAmbQcZf7TPbV4GKcRXsecLVEQWlx vFMA== 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=vu3zC9pM2UbeuPAtGA6ONAVY/TNyoLTb1Mat++/dTkU=; b=Nlet+gXpHFdvmK+/5DldTbvzzmzkcDXxp+/9OMbxxAFsK7MpIg9gL6KS2pnXYxgab6 Y55Ni6gK9qgjOzfyflUdi5CV60aJdgfOEskebKL1CD1BHhqhKVn0ZZB45W3pakGx0uTH a8jtY8nYZ8tbJ0sOzUqEodWwa7f1mYLlLhl3D+nKB94jbDNOdi8ioavS2xggZYwngtw6 8fh/qWBUgQyvrYgLs6u3n0dyOmd53x/u+NK5krJ/yqMVfGEyV9EpoOfZfjLsO3J9+79S vfQy4VLrTYBBbGrmH76ra/siJ21sIVndAwPVtRZPkDqt0gpAItHit6sq7l6ptPlol1K+ xwmA== X-Gm-Message-State: APjAAAUW+XxLW+o50DFBmZi1zrONFXjNmVoqabApGHQb+I1+SACRO2bp QufULdRjpX3RX4njTAYgR+N9F551 X-Google-Smtp-Source: APXvYqzrv3wTNuwu5ZCtwqCLEqL/u6eKkVUryzpUMKWTBvREf+YR5jSomC+j/ZelfvyHO6RPpw31rg== X-Received: by 2002:aa7:8e50:: with SMTP id d16mr121827030pfr.65.1561024546763; Thu, 20 Jun 2019 02:55:46 -0700 (PDT) Received: from ash ([115.76.181.38]) by smtp.gmail.com with ESMTPSA id k4sm12097503pfk.42.2019.06.20.02.55.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 02:55:46 -0700 (PDT) Received: by ash (sSMTP sendmail emulation); Thu, 20 Jun 2019 16:55:42 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 4/4] restore: add --intent-to-add (restoring worktree only) Date: Thu, 20 Jun 2019 16:55:23 +0700 Message-Id: <20190620095523.10003-5-pclouds@gmail.com> X-Mailer: git-send-email 2.22.0.rc0.322.g2b0371e29a In-Reply-To: <20190620095523.10003-1-pclouds@gmail.com> References: <20190620095523.10003-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 restore --source" (without --staged) could create new files (i.e. not present in index) on worktree to match the given source. But the new files are not tracked, so both "git diff" and "git diff " ignore new files. "git commit -a" will not recreate a commit exactly as the given source either. Add --intent-to-add to help track new files in this case, which is the default on the least surprise principle. Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation/git-restore.txt | 7 ++++ builtin/checkout.c | 78 +++++++++++++++++++++++++++++++++++ t/t2070-restore.sh | 17 ++++++++ 3 files changed, 102 insertions(+) diff --git a/Documentation/git-restore.txt b/Documentation/git-restore.txt index d90093f195..43a7f43b2b 100644 --- a/Documentation/git-restore.txt +++ b/Documentation/git-restore.txt @@ -93,6 +93,13 @@ in linkgit:git-checkout[1] for details. are "merge" (default) and "diff3" (in addition to what is shown by "merge" style, shows the original contents). +--intent-to-add:: +--no-intent-to-add:: + When restoring files only on working tree with `--source`, + new files are marked as "intent to add" (see + linkgit:git-add[1]). This is the default behavior. Use + `--no-intent-to-add` to disable it. + --ignore-unmerged:: When restoring files on the working tree from the index, do not abort the operation if there are unmerged entries and diff --git a/builtin/checkout.c b/builtin/checkout.c index f884d27f1f..c519067d3d 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -70,6 +70,7 @@ struct checkout_opts { int checkout_worktree; const char *ignore_unmerged_opt; int ignore_unmerged; + int intent_to_add; const char *new_branch; const char *new_branch_force; @@ -392,6 +393,69 @@ static int checkout_worktree(const struct checkout_opts *opts) return errs; } +/* + * Input condition: r->index contains the file list matching worktree. + * + * r->index is reloaded with $GIT_DIR/index. Files that exist in the + * current worktree but not in $GIT_DIR/index are added back as + * intent-to-add. + */ +static int add_intent_to_add_files(struct repository *r) +{ + char **file_list; + int pos, worktree_nr, ita_nr = 0; + int ret = 0; + + worktree_nr = r->index->cache_nr; + ALLOC_ARRAY(file_list, worktree_nr); + for (pos = 0; pos < worktree_nr; pos++) + file_list[pos] = xstrdup(r->index->cache[pos]->name); + + discard_index(r->index); + if (repo_read_index(r) < 0) { + ret = error(_("index file corrupt")); + goto done; + } + + for (pos = 0; pos < worktree_nr; ) { + const char *worktree = file_list[pos]; + int index_pos = index_name_pos(r->index, worktree, strlen(worktree)); + + if (index_pos < 0) { + if (add_file_to_index(r->index, worktree, ADD_CACHE_INTENT)) + ret = error(_("failed to add %s"), worktree); + else + ita_nr++; + pos++; + continue; + } + + /* + * Try to speed up the scanning process a bit. + * + * The assumption here is file_list[] and r->index->cache[] + * are 90% the same. We can just skip a big chunk of the same + * entries and reduce the number of binary lookups. + */ + pos++; + index_pos++; + while (pos < worktree_nr && index_pos < r->index->cache_nr && + !fspathcmp(file_list[pos], r->index->cache[index_pos]->name)) { + pos++; + index_pos++; + } + } + + if (!ret) + ret = ita_nr; + +done: + for (pos = 0; pos < worktree_nr; pos++) + free(file_list[pos]); + free(file_list); + return ret; +} + static int checkout_paths(const struct checkout_opts *opts, const char *revision) { @@ -531,6 +595,16 @@ static int checkout_paths(const struct checkout_opts *opts, else checkout_index = opts->checkout_index; + if (opts->intent_to_add && opts->from_treeish && + !opts->checkout_index && opts->checkout_worktree) { + int ita_nr = add_intent_to_add_files(the_repository); + + if (ita_nr > 0) + checkout_index = 1; + if (ita_nr < 0) + errs = -1; + } + if (checkout_index) { if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); @@ -1697,6 +1771,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) opts.overlay_mode = -1; opts.checkout_index = -2; /* default on */ opts.checkout_worktree = -2; /* default on */ + opts.intent_to_add = 0; options = parse_options_dup(checkout_options); options = add_common_options(&opts, options); @@ -1758,6 +1833,8 @@ int cmd_restore(int argc, const char **argv, const char *prefix) N_("restore the index")), OPT_BOOL('W', "worktree", &opts.checkout_worktree, N_("restore the working tree (default)")), + OPT_BOOL(0, "intent-to-add", &opts.intent_to_add, + N_("mark new files on working tree as intent-to-add (default)")), OPT_BOOL(0, "ignore-unmerged", &opts.ignore_unmerged, N_("ignore unmerged entries")), OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode")), @@ -1773,6 +1850,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix) opts.checkout_index = -1; /* default off */ opts.checkout_worktree = -2; /* default on */ opts.ignore_unmerged_opt = "--ignore-unmerged"; + opts.intent_to_add = 1; options = parse_options_dup(restore_options); options = add_common_options(&opts, options); diff --git a/t/t2070-restore.sh b/t/t2070-restore.sh index 2650df1966..acbd80c1cd 100755 --- a/t/t2070-restore.sh +++ b/t/t2070-restore.sh @@ -95,4 +95,21 @@ test_expect_success 'restore --ignore-unmerged ignores unmerged entries' ' ) ' +test_expect_success 'restore worktree only adds new files back as intent-to-add' ' + git init ita && + ( + cd ita && + test_commit one && + test_commit two && + git rm one.t && + git commit -m one-is-gone && + git restore --source one one.t && + git diff --summary >actual && + echo " create mode 100644 one.t" >expected && + test_cmp expected actual && + git diff --cached >empty && + test_must_be_empty empty + ) +' + test_done