From patchwork Sun Jun 16 08:20:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Ashiwal X-Patchwork-Id: 10997299 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 C033914B6 for ; Sun, 16 Jun 2019 08:23:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1FDA28735 for ; Sun, 16 Jun 2019 08:23:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A52D32876E; Sun, 16 Jun 2019 08:23: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 4AE1B28735 for ; Sun, 16 Jun 2019 08:23:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726311AbfFPIXg (ORCPT ); Sun, 16 Jun 2019 04:23:36 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46380 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbfFPIXf (ORCPT ); Sun, 16 Jun 2019 04:23:35 -0400 Received: by mail-pl1-f194.google.com with SMTP id e5so2804695pls.13 for ; Sun, 16 Jun 2019 01:23:35 -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=DTkwOxGH2Q7/D1UjALjxmCJPB6FE7W1q/xt1a0q6B3Y=; b=fANCADrG39OjTmy8dxx8MKj2iz20GHtb67Y99p3GI5uCxJOoPubFMYHcSxM7O6Pr4j T18S1MIskjr93DN9a2LggbEy4m/bYAaWJdOUgq/nTVGaZyCiM6QaMBd+isfz91Rk9ACS IVDLR1jOCCecjOHbCXWr6lyvM8dML0JdQe2Rs2v2w8sb1T8rUOVH1VBaWfNqYiOJOj0J DeWE4gdtSSknqDEa2BBul/InSFBNyJ7+Xg2xBve//5vO9cbfbuetzdBo7VQl3Tm9h759 nwhOTAhfHRamgi7kWkP2+oARMfDDVoGqunyyqrHBRXc/x/iss0AAriQO2jGQ8edqdTbM 89dg== 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=DTkwOxGH2Q7/D1UjALjxmCJPB6FE7W1q/xt1a0q6B3Y=; b=NdAZYhozKV7/AXMz+in3Z8+LslrUe7Qewi48i6m12WBSVvmOBOsmk/OI2GQAOt2Ctf XueeCsObtD1hvn7HviakPTLlclsS8lFFMGFKvc+MfDjel/VhkRmgJgusFPMZmqboTiMf 9P9H0iUXIrTFmG2IJt8HoWeOTm/Kmwees5ORiatoVqp9nM+kqRTWnq0zJbuf1tDWjylJ /2Z9ovuPXghLSJ9H73X7ELQ+kflIYyUGJG4TzyfJ0pgDnbmq7kWUxXMK76/31KjYe9y7 vWLnY9Ifbd0fcm/3/I1g37FXbOVKVISnbESaw2xTC+QXtkgWsdUOziK2XELQmylVVz2I OHrg== X-Gm-Message-State: APjAAAXIsdQj99wLmyz6/1C8RZtFsQB5XSsjD/e+WRRNDEHTJ2wJKesc W4zmEBIwL3PPpaBuaJuDadL/C1GGNJJ0UA== X-Google-Smtp-Source: APXvYqxkHzSjFENYo+qLf4HyRHK4BMuuQd6jkVLamkvjM8GP38Vy3nrPKtYKaFb/Cefav/8atGrymw== X-Received: by 2002:a17:902:728a:: with SMTP id d10mr99940479pll.90.1560673415090; Sun, 16 Jun 2019 01:23:35 -0700 (PDT) Received: from ar135.iitr.local ([2401:4900:3105:6dd7:b496:8be7:332f:b415]) by smtp.gmail.com with ESMTPSA id x128sm1471972pfd.17.2019.06.16.01.23.31 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 01:23:34 -0700 (PDT) From: Rohit Ashiwal To: rohit.ashiwal265@gmail.com Cc: git@vger.kernel.org, newren@gmail.com, t.gummerer@gmail.com, phillip.wood123@gmail.com, martin.agren@gmail.com, jrnieder@gmail.com, gitster@pobox.com Subject: [GSoC][PATCH v4 1/4] sequencer: add advice for revert Date: Sun, 16 Jun 2019 13:50:37 +0530 Message-Id: <20190616082040.9440-2-rohit.ashiwal265@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190616082040.9440-1-rohit.ashiwal265@gmail.com> References: <20190608191958.4593-1-rohit.ashiwal265@gmail.com> <20190616082040.9440-1-rohit.ashiwal265@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 the case of merge conflicts, while performing a revert, we are currently advised to use `git cherry-pick --` of which --continue is incompatible for continuing the revert. Introduce a separate advice message for `git revert`. Also change the signature of `create_seq_dir` to handle which advice to display selectively. Signed-off-by: Rohit Ashiwal --- changes: - change BUG()'s message under create_seq_dir sequencer.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/sequencer.c b/sequencer.c index f88a97fb10..d80e1c3fbb 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2650,15 +2650,37 @@ static int walk_revs_populate_todo(struct todo_list *todo_list, return 0; } -static int create_seq_dir(void) +static int create_seq_dir(struct repository *r) { - if (file_exists(git_path_seq_dir())) { - error(_("a cherry-pick or revert is already in progress")); - advise(_("try \"git cherry-pick (--continue | --quit | --abort)\"")); + enum replay_action action; + const char *in_progress_error = NULL; + const char *in_progress_advice = NULL; + + if (!sequencer_get_last_command(r, &action)) { + switch (action) { + case REPLAY_REVERT: + in_progress_error = _("revert is already in progress"); + in_progress_advice = + _("try \"git revert (--continue | --abort | --quit)\""); + break; + case REPLAY_PICK: + in_progress_error = _("cherry-pick is already in progress"); + in_progress_advice = + _("try \"git cherry-pick (--continue | --abort | --quit)\""); + break; + default: + BUG(_("unexpected action in create_seq_dir")); + } + } + if (in_progress_error) { + error("%s", in_progress_error); + advise("%s", in_progress_advice); return -1; - } else if (mkdir(git_path_seq_dir(), 0777) < 0) + } + if (mkdir(git_path_seq_dir(), 0777) < 0) return error_errno(_("could not create sequencer directory '%s'"), git_path_seq_dir()); + return 0; } @@ -4237,7 +4259,7 @@ int sequencer_pick_revisions(struct repository *r, */ if (walk_revs_populate_todo(&todo_list, opts) || - create_seq_dir() < 0) + create_seq_dir(r) < 0) return -1; if (get_oid("HEAD", &oid) && (opts->action == REPLAY_REVERT)) return error(_("can't revert as initial commit")); From patchwork Sun Jun 16 08:20:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Ashiwal X-Patchwork-Id: 10997301 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 2FC93924 for ; Sun, 16 Jun 2019 08:23:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 232AF28735 for ; Sun, 16 Jun 2019 08:23:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 175282876E; Sun, 16 Jun 2019 08:23:42 +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 B6A7828735 for ; Sun, 16 Jun 2019 08:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726362AbfFPIXk (ORCPT ); Sun, 16 Jun 2019 04:23:40 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44445 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbfFPIXk (ORCPT ); Sun, 16 Jun 2019 04:23:40 -0400 Received: by mail-pg1-f196.google.com with SMTP id n2so4030990pgp.11 for ; Sun, 16 Jun 2019 01:23:40 -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=pazEKeDIH7AbdRnR/iaQGh0fYZ4URowy28AFbGXYC5I=; b=NhAS3gtEePt+VW7ZksKJARgsxoGLEmKlewkeiqcMDTFHG5Bd8sj7TRzi0DUcPSKYE0 QzaB9UL2ugaPqTZc1flVZn3KHdhD/tgRU7VW9MJI70h3uxlGrmb+1sa5IAniJpaozWuz MyUZx2I+I7BtF8AJqg+tkQebqf9kEwTZu/m1XJr8LFLi3zD+QzRx8WEWD5edrChxJ5jo Ex/M9Mw7BVQOUB93JYBOFup4O48qW/S9MszUJJrWyFYqNX8f8wOi3lpNrTT3Lm+4cJ0N To64xwDbmyhmauQcfR3d+rREocAalaLVm0yvCmikmIYYgoUdAg6PpG/+0ob8s+2ysV8a mH/g== 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=pazEKeDIH7AbdRnR/iaQGh0fYZ4URowy28AFbGXYC5I=; b=B2lMy4SKnWUjyJQHgGzsfhiLfDXX84ZX9V5dsB/545TkDzZDDdf1CPuB6Q/RyW8XKr k50MpwQG4MIgWNm3m7p/8eEjuUkyQp53viBMNShk2vFLTvF73Dbfl+Ko8rEOVqxKkMKG H/CkF0nf3Jx9bj04nxzw+2Nr2cF8o64s8FZniD1IXLLHnNSQALp9qswlGRHTyF8xAyXg RmsnLOwgWx5mWAERhLx/PKUDENfu0Wd38HvotwsfRQ5M+OmQM4R8GxJ3fYH93Ru5v+Zr LlnU/xWeV7ZOHW+N/71b3PzdL/ELCqOGxxqirWHNrnP+yZzTNFl8/qXl9ybcJtYjG0IZ YAsw== X-Gm-Message-State: APjAAAWtisdqdXRfS3b9d55lVmJymwePVZPQUARtsJAphAfKjakKXW3k r8ad5LvckyFUuotrnF0gLzs= X-Google-Smtp-Source: APXvYqzpzft2B4o0uZ/KtstlMzyWiRKcyI3hNmVwj7RUE8OZbTQxFqvLAfYubatMZWyZXMmc+lm6hw== X-Received: by 2002:a63:6105:: with SMTP id v5mr43684460pgb.312.1560673419659; Sun, 16 Jun 2019 01:23:39 -0700 (PDT) Received: from ar135.iitr.local ([2401:4900:3105:6dd7:b496:8be7:332f:b415]) by smtp.gmail.com with ESMTPSA id x128sm1471972pfd.17.2019.06.16.01.23.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 01:23:39 -0700 (PDT) From: Rohit Ashiwal To: rohit.ashiwal265@gmail.com Cc: git@vger.kernel.org, newren@gmail.com, t.gummerer@gmail.com, phillip.wood123@gmail.com, martin.agren@gmail.com, jrnieder@gmail.com, gitster@pobox.com Subject: [GSoC][PATCH v4 2/4] sequencer: rename reset_for_rollback to reset_merge Date: Sun, 16 Jun 2019 13:50:38 +0530 Message-Id: <20190616082040.9440-3-rohit.ashiwal265@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190616082040.9440-1-rohit.ashiwal265@gmail.com> References: <20190608191958.4593-1-rohit.ashiwal265@gmail.com> <20190616082040.9440-1-rohit.ashiwal265@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 We are on a path to teach cherry-pick/revert how to skip commits. To achieve this, we could really make use of existing functions. reset_for_rollback is one such function, but the name does not intuitively suggest to use it to reset a merge, which it was born to perform, see 539047c ("revert: introduce --abort to cancel a failed cherry-pick", 2011-11-23). Change the name to reset_merge to make it more intuitive. Signed-off-by: Rohit Ashiwal --- sequencer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sequencer.c b/sequencer.c index d80e1c3fbb..408643f88a 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2731,7 +2731,7 @@ static int rollback_is_safe(void) return oideq(&actual_head, &expected_head); } -static int reset_for_rollback(const struct object_id *oid) +static int reset_merge(const struct object_id *oid) { const char *argv[4]; /* reset --merge + NULL */ @@ -2753,7 +2753,7 @@ static int rollback_single_pick(struct repository *r) return error(_("cannot resolve HEAD")); if (is_null_oid(&head_oid)) return error(_("cannot abort from a branch yet to be born")); - return reset_for_rollback(&head_oid); + return reset_merge(&head_oid); } int sequencer_rollback(struct repository *r, struct replay_opts *opts) @@ -2796,7 +2796,7 @@ int sequencer_rollback(struct repository *r, struct replay_opts *opts) warning(_("You seem to have moved HEAD. " "Not rewinding, check your HEAD!")); } else - if (reset_for_rollback(&oid)) + if (reset_merge(&oid)) goto fail; strbuf_release(&buf); return sequencer_remove_state(opts); From patchwork Sun Jun 16 08:20:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Ashiwal X-Patchwork-Id: 10997303 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 5074E924 for ; Sun, 16 Jun 2019 08:23:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 422BB28735 for ; Sun, 16 Jun 2019 08:23:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 363EB2876E; Sun, 16 Jun 2019 08:23:48 +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 5076628735 for ; Sun, 16 Jun 2019 08:23:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726401AbfFPIXq (ORCPT ); Sun, 16 Jun 2019 04:23:46 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39151 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbfFPIXq (ORCPT ); Sun, 16 Jun 2019 04:23:46 -0400 Received: by mail-pg1-f194.google.com with SMTP id 196so4046025pgc.6 for ; Sun, 16 Jun 2019 01:23:45 -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=LTg9S4fcy1AKCCedENSZDDSE41b1F9LwF70DmKcEYnY=; b=jrttvmsgZqXgmDbmXYXKN3Qz77Sfa+zRwFCecwatMIrq2CWW8iXNZR34wfyszKoCUb y0YlWNdIekG1i50souRy2qzhm50hrCNzidzh8/6cNqhPRn6ffs8uxsGsz99ULX0oStAI v8rI2xs/g85m9PzqFCYE8byT58FdFuBUY4dNpP+XYvRfg9aVjeM8LNka2MXlJmTO1oXT wIfiFxC5U0hmfT0RZfKye1UmZ5Sk6rj4z7CTf+C/xiOKWSMj3NZd/nMhTNLISPN9brtw 8uvkpwpcc4VZPYGWz6iCCiospdr03oVzIyNJLg/hMxyjQtKr3rdt39hSKPtzi4LxtXy8 HpBg== 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=LTg9S4fcy1AKCCedENSZDDSE41b1F9LwF70DmKcEYnY=; b=GbfpQYD+cuB9qiRiWzRecHCx9xsA8QzFgaGZacBB7GqxwXJLtz/3fCq2WVCMKEWBw5 cWCMznIkOjpMQkhJpHvE8hd3zAGYuDRXubtxKHELdxLdAqGC0bIIN20ed7XRcREDIbum 73YGNM8mP92uSIEwYbfW1qtQZTrJlCNwXi5YPfMROARRcJcTGrfNrsnXkRDoNJEDlNFF vPvZruaNi/qrNLPLtomCfyPLKe0QAlhlHk98JhftOpagFXFNDf0GgWhmx7hEGXjT59Wz xgWuud1nwwsT+rk96XoOATn52xdNSphpI8ywP1O4zCyTT689Sr/Z3kOUxOKmR/UYdykc W+wg== X-Gm-Message-State: APjAAAX0N7fWLOr2KUTaIuAjUylk0O0zYw+YJYqoG2FPowbzvH5vR8/l 8hjABxph+hAYVbyQv2/VobXO4Fcc+/ul3w== X-Google-Smtp-Source: APXvYqypI2hJRtElu8uqZscffJPwuwnY2AzPe7WTbYzAzTaB5lciKxPn/OPxMLRbgngV4WfAD/J2ww== X-Received: by 2002:a17:90a:8415:: with SMTP id j21mr19885283pjn.21.1560673424891; Sun, 16 Jun 2019 01:23:44 -0700 (PDT) Received: from ar135.iitr.local ([2401:4900:3105:6dd7:b496:8be7:332f:b415]) by smtp.gmail.com with ESMTPSA id x128sm1471972pfd.17.2019.06.16.01.23.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 01:23:44 -0700 (PDT) From: Rohit Ashiwal To: rohit.ashiwal265@gmail.com Cc: git@vger.kernel.org, newren@gmail.com, t.gummerer@gmail.com, phillip.wood123@gmail.com, martin.agren@gmail.com, jrnieder@gmail.com, gitster@pobox.com Subject: [GSoC][PATCH v4 3/4] cherry-pick/revert: add --skip option Date: Sun, 16 Jun 2019 13:50:39 +0530 Message-Id: <20190616082040.9440-4-rohit.ashiwal265@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190616082040.9440-1-rohit.ashiwal265@gmail.com> References: <20190608191958.4593-1-rohit.ashiwal265@gmail.com> <20190616082040.9440-1-rohit.ashiwal265@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 am or rebase have a --skip flag to skip the current commit if the user wishes to do so. During a cherry-pick or revert a user could likewise skip a commit, but needs to use 'git reset' (or in the case of conflicts 'git reset --merge'), followed by 'git (cherry-pick | revert) --continue' to skip the commit. This is more annoying and sometimes confusing on the users' part. Add a `--skip` option to make skipping commits easier for the user and to make the commands more consistent. In the next commit, we will change the advice messages and some tests hence finishing the process of teaching revert and cherry-pick "how to skip commits". Signed-off-by: Rohit Ashiwal --- changes: - Introduce '('s around documentation/help - Introduce a wrapper function skip_single_pick to reset_merge - Add comments to sequencer_skip - Change tests to use test_i18ncmp instead of test_cmp to not fail under GETTEXT_POISON Documentation/git-cherry-pick.txt | 4 +- Documentation/git-revert.txt | 4 +- Documentation/sequencer.txt | 4 ++ builtin/revert.c | 5 ++ sequencer.c | 94 +++++++++++++++++++++++++-- sequencer.h | 1 + t/t3510-cherry-pick-sequence.sh | 102 ++++++++++++++++++++++++++++++ 7 files changed, 202 insertions(+), 12 deletions(-) diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt index 754b16ce0c..83ce51aedf 100644 --- a/Documentation/git-cherry-pick.txt +++ b/Documentation/git-cherry-pick.txt @@ -10,9 +10,7 @@ SYNOPSIS [verse] 'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] [-S[]] ... -'git cherry-pick' --continue -'git cherry-pick' --quit -'git cherry-pick' --abort +'git cherry-pick' (--continue | --skip | --abort | --quit) DESCRIPTION ----------- diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt index 0c82ca5bc0..665e065ee3 100644 --- a/Documentation/git-revert.txt +++ b/Documentation/git-revert.txt @@ -9,9 +9,7 @@ SYNOPSIS -------- [verse] 'git revert' [--[no-]edit] [-n] [-m parent-number] [-s] [-S[]] ... -'git revert' --continue -'git revert' --quit -'git revert' --abort +'git revert' (--continue | --skip | --abort | --quit) DESCRIPTION ----------- diff --git a/Documentation/sequencer.txt b/Documentation/sequencer.txt index 5a57c4a407..3bceb56474 100644 --- a/Documentation/sequencer.txt +++ b/Documentation/sequencer.txt @@ -3,6 +3,10 @@ `.git/sequencer`. Can be used to continue after resolving conflicts in a failed cherry-pick or revert. +--skip:: + Skip the current commit and continue with the rest of the + sequence. + --quit:: Forget about the current operation in progress. Can be used to clear the sequencer state after a failed cherry-pick or diff --git a/builtin/revert.c b/builtin/revert.c index d4dcedbdc6..5dc5891ea2 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -102,6 +102,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) OPT_CMDMODE(0, "quit", &cmd, N_("end revert or cherry-pick sequence"), 'q'), OPT_CMDMODE(0, "continue", &cmd, N_("resume revert or cherry-pick sequence"), 'c'), OPT_CMDMODE(0, "abort", &cmd, N_("cancel revert or cherry-pick sequence"), 'a'), + OPT_CMDMODE(0, "skip", &cmd, N_("skip current commit and continue"), 's'), OPT_CLEANUP(&cleanup_arg), OPT_BOOL('n', "no-commit", &opts->no_commit, N_("don't automatically commit")), OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")), @@ -151,6 +152,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) this_operation = "--quit"; else if (cmd == 'c') this_operation = "--continue"; + else if (cmd == 's') + this_operation = "--skip"; else { assert(cmd == 'a'); this_operation = "--abort"; @@ -210,6 +213,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) return sequencer_continue(the_repository, opts); if (cmd == 'a') return sequencer_rollback(the_repository, opts); + if (cmd == 's') + return sequencer_skip(the_repository, opts); return sequencer_pick_revisions(the_repository, opts); } diff --git a/sequencer.c b/sequencer.c index 408643f88a..95fa19a118 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2733,13 +2733,18 @@ static int rollback_is_safe(void) static int reset_merge(const struct object_id *oid) { - const char *argv[4]; /* reset --merge + NULL */ + int ret; + struct argv_array argv = ARGV_ARRAY_INIT; - argv[0] = "reset"; - argv[1] = "--merge"; - argv[2] = oid_to_hex(oid); - argv[3] = NULL; - return run_command_v_opt(argv, RUN_GIT_CMD); + argv_array_pushl(&argv, "reset", "--merge", NULL); + + if (!is_null_oid(oid)) + argv_array_push(&argv, oid_to_hex(oid)); + + ret = run_command_v_opt(argv.argv, RUN_GIT_CMD); + argv_array_clear(&argv); + + return ret; } static int rollback_single_pick(struct repository *r) @@ -2756,6 +2761,15 @@ static int rollback_single_pick(struct repository *r) return reset_merge(&head_oid); } +static int skip_single_pick(void) +{ + struct object_id head; + + if (read_ref_full("HEAD", 0, &head, NULL)) + return error(_("cannot resolve HEAD")); + return reset_merge(&head); +} + int sequencer_rollback(struct repository *r, struct replay_opts *opts) { FILE *f; @@ -2805,6 +2819,74 @@ int sequencer_rollback(struct repository *r, struct replay_opts *opts) return -1; } +int sequencer_skip(struct repository *r, struct replay_opts *opts) +{ + enum replay_action action = -1; + sequencer_get_last_command(r, &action); + + /* + * opts->action tells us which subcommand requested to skip + * the commit. + */ + switch (opts->action) { + case REPLAY_REVERT: + /* + * If .git/REVERT_HEAD exists then we are sure that we are in + * the middle of a revert and we allow to skip the commit. + */ + if (!file_exists(git_path_revert_head(r))) { + /* + * Check if the last instruction executed was related to + * revert. If so, we are sure that a revert is in progress. + * + * NB: single commit revert is also counted in this + * definition of "progress" (and was dealt with in the + * previous check). + */ + if (action == REPLAY_REVERT) { + /* + * Check if the user has moved the HEAD, i.e., + * already committed. In this case, we would like + * to advise instead of skipping. + */ + if (!rollback_is_safe()) + goto give_advice; + else + /* skip commit :) */ + break; + } + return error(_("no revert in progress")); + } + break; + case REPLAY_PICK: + if (!file_exists(git_path_cherry_pick_head(r))) { + if (action == REPLAY_PICK) { + if (!rollback_is_safe()) + goto give_advice; + else + break; + } + return error(_("no cherry-pick in progress")); + } + break; + default: + BUG("unexpected action in sequencer_skip"); + } + + if (skip_single_pick()) + return error(_("failed to skip the commit")); + if (!is_directory(git_path_seq_dir())) + return 0; + + return sequencer_continue(r, opts); + +give_advice: + advise(_("have you committed already?\n" + "try \"git %s --continue\""), + action == REPLAY_REVERT ? "revert" : "cherry-pick"); + return error(_("there is nothing to skip")); +} + static int save_todo(struct todo_list *todo_list, struct replay_opts *opts) { struct lock_file todo_lock = LOCK_INIT; diff --git a/sequencer.h b/sequencer.h index 0c494b83d4..731b9853eb 100644 --- a/sequencer.h +++ b/sequencer.h @@ -129,6 +129,7 @@ int sequencer_pick_revisions(struct repository *repo, struct replay_opts *opts); int sequencer_continue(struct repository *repo, struct replay_opts *opts); int sequencer_rollback(struct repository *repo, struct replay_opts *opts); +int sequencer_skip(struct repository *repo, struct replay_opts *opts); int sequencer_remove_state(struct replay_opts *opts); #define TODO_LIST_KEEP_EMPTY (1U << 0) diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 941d5026da..dc0ac8343c 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -93,6 +93,108 @@ test_expect_success 'cherry-pick cleans up sequencer state upon success' ' test_path_is_missing .git/sequencer ' +test_expect_success 'cherry-pick --skip requires cherry-pick in progress' ' + pristine_detach initial && + test_must_fail git cherry-pick --skip +' + +test_expect_success 'revert --skip requires revert in progress' ' + pristine_detach initial && + test_must_fail git revert --skip +' + +test_expect_success 'cherry-pick --skip to skip commit' ' + pristine_detach initial && + test_must_fail git cherry-pick anotherpick && + test_must_fail git revert --skip && + git cherry-pick --skip && + test_cmp_rev initial HEAD && + test_path_is_missing .git/CHERRY_PICK_HEAD +' + +test_expect_success 'revert --skip to skip commit' ' + pristine_detach anotherpick && + test_must_fail git revert anotherpick~1 && + test_must_fail git cherry-pick --skip && + git revert --skip && + test_cmp_rev anotherpick HEAD +' + +test_expect_success 'skip "empty" commit' ' + pristine_detach picked && + test_commit dummy foo d && + test_must_fail git cherry-pick anotherpick && + git cherry-pick --skip && + test_cmp_rev dummy HEAD +' + +test_expect_success 'skip a commit and check if rest of sequence is correct' ' + pristine_detach initial && + echo e >expect && + cat >expect.log <<-EOF && + OBJID + :100644 100644 OBJID OBJID M foo + OBJID + :100644 100644 OBJID OBJID M foo + OBJID + :100644 100644 OBJID OBJID M unrelated + OBJID + :000000 100644 OBJID OBJID A foo + :000000 100644 OBJID OBJID A unrelated + EOF + test_must_fail git cherry-pick base..yetanotherpick && + test_must_fail git cherry-pick --skip && + echo d >foo && + git add foo && + git cherry-pick --continue && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$OID_REGEX/OBJID/g" + } >actual.log && + test_cmp expect foo && + test_cmp expect.log actual.log +' + +test_expect_success 'check advice when we move HEAD by committing' ' + pristine_detach initial && + cat >expect <<-EOF && + hint: have you committed already? + hint: try "git cherry-pick --continue" + error: there is nothing to skip + fatal: cherry-pick failed + EOF + test_must_fail git cherry-pick base..yetanotherpick && + echo c >foo && + git commit -a && + test_path_is_missing .git/CHERRY_PICK_HEAD && + test_must_fail git cherry-pick --skip 2>advice && + test_i18ncmp expect advice +' + +test_expect_success 'allow skipping commit but not abort for a new history' ' + pristine_detach initial && + cat >expect <<-EOF && + error: cannot abort from a branch yet to be born + fatal: cherry-pick failed + EOF + git checkout --orphan new_disconnected && + git reset --hard && + test_must_fail git cherry-pick anotherpick && + test_must_fail git cherry-pick --abort 2>advice && + git cherry-pick --skip && + test_i18ncmp expect advice +' + +test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' ' + pristine_detach initial && + git rm --cached unrelated && + git commit -m "untrack unrelated" && + test_must_fail git cherry-pick initial base && + test_path_is_missing .git/CHERRY_PICK_HEAD && + git cherry-pick --skip +' + test_expect_success '--quit does not complain when no cherry-pick is in progress' ' pristine_detach initial && git cherry-pick --quit From patchwork Sun Jun 16 08:20:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Ashiwal X-Patchwork-Id: 10997305 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 125C01398 for ; Sun, 16 Jun 2019 08:23:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0526928735 for ; Sun, 16 Jun 2019 08:23:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED6452876E; Sun, 16 Jun 2019 08:23:51 +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 7EEC928735 for ; Sun, 16 Jun 2019 08:23:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726434AbfFPIXu (ORCPT ); Sun, 16 Jun 2019 04:23:50 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33589 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbfFPIXu (ORCPT ); Sun, 16 Jun 2019 04:23:50 -0400 Received: by mail-pl1-f193.google.com with SMTP id c14so2831561plo.0 for ; Sun, 16 Jun 2019 01:23:49 -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=p9YtesxB9C+QY9/Ffpf6BFsi5V3DahDDmTM7TVcLlWM=; b=etneDILG+hDDIuIIgOi8uH0H5SUHvwq+JRnMmndbZPY15t8OwVWaiDiaEVvzaENuvt EXtNxMhFmW/4Trj4ua8tn3rI8DKoyQZri+ZMXHDNWejH7gC02gkFjwxp6BdckgfUCs3c Bz7+fQcdSB9Gg2XGJWLtRxggB6RiqNbkKgC75cdAPwNSIoY78EiHYwJQ8+i0tIPd+XTc i2sfXAwN/0hvrlDu9QuSTXMIZyF+0FTivUeZOmFzhygT7Cxxdq7YpZGsIy76P7Elcrxw TBjhe1blX2ip/kIy4xjZo5bRZvACvklOcumTTFCDDsMMqhusp4nOm4WAh/aUDghJnkVF qjfg== 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=p9YtesxB9C+QY9/Ffpf6BFsi5V3DahDDmTM7TVcLlWM=; b=MUPf73TOihgI9WlozjVwtim9sUCRlJZcyJ0dJ8J6PwZTjUZRXN8hSvUXMx85hi1VUm YSAw8AzFcDHdlEBz0bVo/sI4/OsXhX2x2FWgjwmFbL+JRMWfk3e2mHQeuYiCjYpYFAzN 9NAuxO6DktnjTPMZbSGyPmqMcmpERY0eCPO1ZZqBbUPIqfDwrAWWDdc6rgmfjjgPNshf UTxog4GyUBmhICdbyvKboAphyU7cKxtfCePZEF8fxPckxjcDa/xT0OFqy/GWaEDqQtzG rM14GycxPGQ91iiqF+bg2/b615E8cmf24ybbmRAlJPdWtXb8j2nXxmN+A93QHc635Vqv 7X3A== X-Gm-Message-State: APjAAAVQXWmYUnyyKeDfBpPjZ7a6udIPLvC05yqulqhrjaqOEe8PC9OY rbkCcXKY1heik1RsnrpQYaA= X-Google-Smtp-Source: APXvYqzrFeSTD3Ygo3HHgY+A94bWgMEFbXMJmIc+7GoYzhl9ksxt5co78yU7S2sp9HG0TvXkI6wCwg== X-Received: by 2002:a17:902:e490:: with SMTP id cj16mr100200606plb.136.1560673429285; Sun, 16 Jun 2019 01:23:49 -0700 (PDT) Received: from ar135.iitr.local ([2401:4900:3105:6dd7:b496:8be7:332f:b415]) by smtp.gmail.com with ESMTPSA id x128sm1471972pfd.17.2019.06.16.01.23.45 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 01:23:48 -0700 (PDT) From: Rohit Ashiwal To: rohit.ashiwal265@gmail.com Cc: git@vger.kernel.org, newren@gmail.com, t.gummerer@gmail.com, phillip.wood123@gmail.com, martin.agren@gmail.com, jrnieder@gmail.com, gitster@pobox.com Subject: [GSoC][PATCH v4 4/4] cherry-pick/revert: advise using --skip Date: Sun, 16 Jun 2019 13:50:40 +0530 Message-Id: <20190616082040.9440-5-rohit.ashiwal265@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190616082040.9440-1-rohit.ashiwal265@gmail.com> References: <20190608191958.4593-1-rohit.ashiwal265@gmail.com> <20190616082040.9440-1-rohit.ashiwal265@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 previous commit introduced a --skip flag for cherry-pick and revert. Update the advice messages, to tell users about this less cumbersome way of skipping commits. Also add tests to ensure everything is working fine. Signed-off-by: Rohit Ashiwal --- changes: - Use test_i18ncmp instead of tmp_cmp builtin/commit.c | 13 ++++++++----- sequencer.c | 11 ++++++++--- t/t3510-cherry-pick-sequence.sh | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 1c9e8e2228..1f47c51bdc 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -60,15 +60,18 @@ N_("The previous cherry-pick is now empty, possibly due to conflict resolution.\ "\n"); static const char empty_cherry_pick_advice_single[] = -N_("Otherwise, please use 'git reset'\n"); +N_("Otherwise, please use 'git cherry-pick --skip'\n"); static const char empty_cherry_pick_advice_multi[] = -N_("If you wish to skip this commit, use:\n" +N_("and then use:\n" "\n" -" git reset\n" +" git cherry-pick --continue\n" "\n" -"Then \"git cherry-pick --continue\" will resume cherry-picking\n" -"the remaining commits.\n"); +"to resume cherry-picking the remaining commits.\n" +"If you wish to skip this commit, use:\n" +"\n" +" git cherry-pick --skip\n" +"\n"); static const char *color_status_slots[] = { [WT_STATUS_HEADER] = "header", diff --git a/sequencer.c b/sequencer.c index 95fa19a118..6e8afe8f22 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2655,18 +2655,20 @@ static int create_seq_dir(struct repository *r) enum replay_action action; const char *in_progress_error = NULL; const char *in_progress_advice = NULL; + unsigned int advise_skip = file_exists(git_path_revert_head(r)) || + file_exists(git_path_cherry_pick_head(r)); if (!sequencer_get_last_command(r, &action)) { switch (action) { case REPLAY_REVERT: in_progress_error = _("revert is already in progress"); in_progress_advice = - _("try \"git revert (--continue | --abort | --quit)\""); + _("try \"git revert (--continue | %s--abort | --quit)\""); break; case REPLAY_PICK: in_progress_error = _("cherry-pick is already in progress"); in_progress_advice = - _("try \"git cherry-pick (--continue | --abort | --quit)\""); + _("try \"git cherry-pick (--continue | %s--abort | --quit)\""); break; default: BUG(_("unexpected action in create_seq_dir")); @@ -2674,7 +2676,10 @@ static int create_seq_dir(struct repository *r) } if (in_progress_error) { error("%s", in_progress_error); - advise("%s", in_progress_advice); + if (advise_skip) + advise(in_progress_advice, "--skip | "); + else + advise(in_progress_advice, ""); return -1; } if (mkdir(git_path_seq_dir(), 0777) < 0) diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index dc0ac8343c..0e8adc95fc 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -172,6 +172,26 @@ test_expect_success 'check advice when we move HEAD by committing' ' test_i18ncmp expect advice ' +test_expect_success 'selectively advise --skip while launching another sequence' ' + pristine_detach initial && + cat >expect <<-EOF && + error: cherry-pick is already in progress + hint: try "git cherry-pick (--continue | --skip | --abort | --quit)" + fatal: cherry-pick failed + EOF + test_must_fail git cherry-pick picked..yetanotherpick && + test_must_fail git cherry-pick picked..yetanotherpick 2>advice && + test_i18ncmp expect advice && + cat >expect <<-EOF && + error: cherry-pick is already in progress + hint: try "git cherry-pick (--continue | --abort | --quit)" + fatal: cherry-pick failed + EOF + git reset --merge && + test_must_fail git cherry-pick picked..yetanotherpick 2>advice && + test_i18ncmp expect advice +' + test_expect_success 'allow skipping commit but not abort for a new history' ' pristine_detach initial && cat >expect <<-EOF &&