From patchwork Wed May 1 13:11:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10925067 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 4604D92A for ; Wed, 1 May 2019 13:12:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 308AE28EA6 for ; Wed, 1 May 2019 13:12:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20FD628EB8; Wed, 1 May 2019 13:12:08 +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 99BE828EA6 for ; Wed, 1 May 2019 13:12:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726458AbfEANMG (ORCPT ); Wed, 1 May 2019 09:12:06 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39200 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726101AbfEANMG (ORCPT ); Wed, 1 May 2019 09:12:06 -0400 Received: by mail-pf1-f196.google.com with SMTP id z26so4706807pfg.6 for ; Wed, 01 May 2019 06:12:05 -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=6QQqG96I/vuxysDJ/ikR8DpfmKzcXBv+IkmOY6ylQOQ=; b=c1ijCDOYxk/g7XwHAXRI/x0rG1yV7JUlg0k5PoDp7JaT4uSebRyrQT9rhFr+7PFsLt eCrkZmJEtNqbqvDRUKgQlQYql6IUnXdelWzh1eNGP2jdrBTMg01y+gAh53fUU+nF/bN7 FalEnHjIyGVcGuGnIwKmeLeL43gJ5Ndy9wc0GhZsVzXlGSQzgi9QfEu24HobIKHRNRpD SkljzqWh1vE67scRXMKbG4RQJTLFqSurJrrMVzVi2pITWN7F6BzTkMnpKoMh+ny6PEB9 MSSy3/20xk+EybfJ2KERZTyE6qxZgsswkiNixLYVFc9CdAgzIaTSwfO4+XjepG8T9l84 LHqw== 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=6QQqG96I/vuxysDJ/ikR8DpfmKzcXBv+IkmOY6ylQOQ=; b=fFGEM2TnD9NLAq4/ERrWnQK8vZfml9LNUil8mlxcZJbprN0t/uKWYhvWSCceZh4WFB puxRl/Hy0fkkbGZrUIVNUKHYYvmTxd49kyymeTHg9NbNRjTQZZxQhFub4rlZJI8+AukA dOpB1k5qYny/YAXvID2MVaYTlWaXClbo3ohj599nN6AiuSK10ppG0ETbHbfaFlvj8eIS hJpIWhZsFdfRT2X/mPcxTwy87uqzXlPfS70kCF/oklBUEx1nSX4YpBkrUqOIAw45g6Y3 VKLoCpe9isY8KLlElHLQ8yDewXWfjG8CnrKmVacrjuJkBljYjHBB5npqvRa5x581BUwG iOrQ== X-Gm-Message-State: APjAAAXIskaphY6r35nJAOz5K3Ig75snDozL6pGPKsPW1BNLlbZ0A6yi som+F+oS2Oa2gh6jLBfaTRsCC9pS X-Google-Smtp-Source: APXvYqxJ/K1Jf4+pgYEEeTYSiD/3zc+R3TDKgw9rf3kVG72hhsxgw3OI+dbNiOTHysam/T0lLuuANw== X-Received: by 2002:a62:e201:: with SMTP id a1mr9493247pfi.67.1556716325236; Wed, 01 May 2019 06:12:05 -0700 (PDT) Received: from ash ([171.226.41.84]) by smtp.gmail.com with ESMTPSA id g3sm28709572pfm.167.2019.05.01.06.12.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 May 2019 06:12:04 -0700 (PDT) Received: by ash (sSMTP sendmail emulation); Wed, 01 May 2019 20:12:00 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Phillip Wood , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= Subject: [PATCH 1/2] merge: remove drop_save() in favor of remove_merge_branch_state() Date: Wed, 1 May 2019 20:11:51 +0700 Message-Id: <20190501131152.314-2-pclouds@gmail.com> X-Mailer: git-send-email 2.21.0.1110.g9614c01b33 In-Reply-To: <20190501131152.314-1-pclouds@gmail.com> References: <20190501131152.314-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 Both remove_branch_state() and drop_save() delete almost the same set of files about the current merge state. The only difference is MERGE_RR but it should also be cleaned up after a successful merge, which is what drop_save() is for. Make a new function that deletes all merge-related state files and use it instead of drop_save(). This function will also be used in the next patch that introduces --quit. Signed-off-by: Nguyễn Thái Ngọc Duy --- branch.c | 11 ++++++++--- branch.h | 6 ++++++ builtin/merge.c | 17 +++++------------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/branch.c b/branch.c index 28b81a7e02..1db0601a11 100644 --- a/branch.c +++ b/branch.c @@ -337,15 +337,20 @@ void create_branch(struct repository *r, free(real_ref); } -void remove_branch_state(struct repository *r) +void remove_merge_branch_state(struct repository *r) { - unlink(git_path_cherry_pick_head(r)); - unlink(git_path_revert_head(r)); unlink(git_path_merge_head(r)); unlink(git_path_merge_rr(r)); unlink(git_path_merge_msg(r)); unlink(git_path_merge_mode(r)); +} + +void remove_branch_state(struct repository *r) +{ + unlink(git_path_cherry_pick_head(r)); + unlink(git_path_revert_head(r)); unlink(git_path_squash_msg(r)); + remove_merge_branch_state(r); } void die_if_checked_out(const char *branch, int ignore_current_worktree) diff --git a/branch.h b/branch.h index 29c1afa4d0..c90ba9d7bf 100644 --- a/branch.h +++ b/branch.h @@ -60,6 +60,12 @@ extern int validate_branchname(const char *name, struct strbuf *ref); */ extern int validate_new_branchname(const char *name, struct strbuf *ref, int force); +/* + * Remove information about the merge state on the current + * branch. (E.g., MERGE_HEAD) + */ +void remove_merge_branch_state(struct repository *r); + /* * Remove information about the state of working on the current * branch. (E.g., MERGE_HEAD) diff --git a/builtin/merge.c b/builtin/merge.c index 5ce8946d39..0fd448b403 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -37,6 +37,7 @@ #include "packfile.h" #include "tag.h" #include "alias.h" +#include "branch.h" #include "commit-reach.h" #define DEFAULT_TWOHEAD (1<<0) @@ -282,14 +283,6 @@ static struct option builtin_merge_options[] = { OPT_END() }; -/* Cleans up metadata that is uninteresting after a succeeded merge. */ -static void drop_save(void) -{ - unlink(git_path_merge_head(the_repository)); - unlink(git_path_merge_msg(the_repository)); - unlink(git_path_merge_mode(the_repository)); -} - static int save_state(struct object_id *stash) { int len; @@ -383,7 +376,7 @@ static void finish_up_to_date(const char *msg) { if (verbosity >= 0) printf("%s%s\n", squash ? _(" (nothing to squash)") : "", msg); - drop_save(); + remove_merge_branch_state(the_repository); } static void squash_message(struct commit *commit, struct commit_list *remoteheads) @@ -861,7 +854,7 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads) &result_commit, NULL, sign_commit)) die(_("failed to write commit object")); finish(head, remoteheads, &result_commit, "In-index merge"); - drop_save(); + remove_merge_branch_state(the_repository); return 0; } @@ -888,7 +881,7 @@ static int finish_automerge(struct commit *head, strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy); finish(head, remoteheads, &result_commit, buf.buf); strbuf_release(&buf); - drop_save(); + remove_merge_branch_state(the_repository); return 0; } @@ -1466,7 +1459,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) } finish(head_commit, remoteheads, &commit->object.oid, msg.buf); - drop_save(); + remove_merge_branch_state(the_repository); goto done; } else if (!remoteheads->next && common->next) ; From patchwork Wed May 1 13:11:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10925069 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 A8E7A92A for ; Wed, 1 May 2019 13:12:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96AAE28EA6 for ; Wed, 1 May 2019 13:12:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B01828EB8; Wed, 1 May 2019 13:12:12 +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 2324628EA6 for ; Wed, 1 May 2019 13:12:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726503AbfEANML (ORCPT ); Wed, 1 May 2019 09:12:11 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46845 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726101AbfEANMK (ORCPT ); Wed, 1 May 2019 09:12:10 -0400 Received: by mail-pg1-f195.google.com with SMTP id n2so8274242pgg.13 for ; Wed, 01 May 2019 06:12:10 -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=vFUAs9R6kymwh6c7YYA95uXPj/YqVJUesYT+t6+6Xt8=; b=HY4Ibn+h+vbqKZfulPoG4cJyKBTTixX5Lcmt57ozC/Ct/lYP1ruN2KRkM6f7dTaeCD Fwt8eA3gntn2oXdUO5udEWSYj3hJ01VvQnWEYA+LWBfACLI4LREa48mLLL7rwLgHvl5U vCmQDnugcki8h4V6qvznPLYPmndiW/2zeHcly3jQnkVybMsPwSJ9gqsU6bE1SoA8HP39 y+H8U9HM+Fb1v4nQzaH8vzcrfWvrKBbw2YFTK6e3G3619epr+iRjZBIDvHxZagxCnr+f a4HYEGQTHrdvjHHZE76QhMuZzdvSQHIZ9PWBOTAhw0xl1SGIogENsZou8FlCDF6eQ0HB zjVw== 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=vFUAs9R6kymwh6c7YYA95uXPj/YqVJUesYT+t6+6Xt8=; b=JOEIH2ysuPZrul6xK59eBlQe16KZprVgnuDXpHapi34IGKay83qEDOnQJymYeoisWP pwiMYrvQhuSqPkSZSWF9vSjbG1LRF9Bjt3SmNh67tt7hV68beKYKFA3W4fGHHDV7vF9v QgwS7MJ/TlOKC2mtMPqz62RIMvEPtWM8T2ShQFIgBub/wKh4fkFGjaRXYwJN6GhUGB4F /QqM/WAA7fdAnA8d1e5xTFVGFrN+faHMaeX/+3Z4w4ZQqAeiyqENIyAl4ULo/BnB+JEs msuxdUQoz0WMi0EZHUkD1ydXyJhIb03w//R6jMtnLc7b1SJcfapV6Sk+hjjX7IY7fsyT bYrA== X-Gm-Message-State: APjAAAV5tY33PB481d0TKewArQhaZ3tdHiZPjiICvYXaEze+U9R6xP02 Dva44RFC3wNDorZwflXyQIjuI/f1 X-Google-Smtp-Source: APXvYqzrmuLxzSb8Y0aVREjzRmloJnM3qN7Tf0c+yS8JCd6yZ2w6BoKokz9zvtXd245x9Em6rLqIyw== X-Received: by 2002:a65:5bc3:: with SMTP id o3mr3920604pgr.40.1556716329956; Wed, 01 May 2019 06:12:09 -0700 (PDT) Received: from ash ([171.226.41.84]) by smtp.gmail.com with ESMTPSA id l10sm90666701pfc.46.2019.05.01.06.12.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 May 2019 06:12:09 -0700 (PDT) Received: by ash (sSMTP sendmail emulation); Wed, 01 May 2019 20:12:05 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Phillip Wood , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= Subject: [PATCH 2/2] merge: add --quit Date: Wed, 1 May 2019 20:11:52 +0700 Message-Id: <20190501131152.314-3-pclouds@gmail.com> X-Mailer: git-send-email 2.21.0.1110.g9614c01b33 In-Reply-To: <20190501131152.314-1-pclouds@gmail.com> References: <20190501131152.314-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 allows to cancel the current merge without reseting worktree/index, which is what --abort is for. Like other --quit(s), this is often used when you forgot that you're in the middle of a merge and already switched away, doing different things. By the time you're realize, you can't even continue the merge anymore. This also makes all in-progress commands, am, merge, rebase, revert and cherry-pick, take all three --abort, --continue and --quit (bisect has a different UI). Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation/git-merge.txt | 4 ++++ builtin/merge.c | 13 +++++++++++++ t/t7600-merge.sh | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index 6294dbc09d..c01cfa6595 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -100,6 +100,10 @@ commit or stash your changes before running 'git merge'. 'git merge --abort' is equivalent to 'git reset --merge' when `MERGE_HEAD` is present. +--quit:: + Forget about the current merge in progress. Leave the index + and the working tree as-is. + --continue:: After a 'git merge' stops due to conflicts you can conclude the merge by running 'git merge --continue' (see "HOW TO RESOLVE diff --git a/builtin/merge.c b/builtin/merge.c index 0fd448b403..13392ba1cf 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -73,6 +73,7 @@ static int option_renormalize; static int verbosity; static int allow_rerere_auto; static int abort_current_merge; +static int quit_current_merge; static int continue_current_merge; static int allow_unrelated_histories; static int show_progress = -1; @@ -270,6 +271,8 @@ static struct option builtin_merge_options[] = { OPT__VERBOSITY(&verbosity), OPT_BOOL(0, "abort", &abort_current_merge, N_("abort the current in-progress merge")), + OPT_BOOL(0, "quit", &quit_current_merge, + N_("--abort but leave index and working tree alone")), OPT_BOOL(0, "continue", &continue_current_merge, N_("continue the current in-progress merge")), OPT_BOOL(0, "allow-unrelated-histories", &allow_unrelated_histories, @@ -1255,6 +1258,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } + if (quit_current_merge) { + if (orig_argc != 2) + usage_msg_opt(_("--quit expects no arguments"), + builtin_merge_usage, + builtin_merge_options); + + remove_merge_branch_state(the_repository); + goto done; + } + if (continue_current_merge) { int nargc = 1; const char *nargv[] = {"commit", NULL}; diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 106148254d..ea82cb744b 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -822,4 +822,18 @@ test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' verify_parents $c0 $c1 ' +test_expect_success 'merge --quit' ' + git reset --hard side && + test_must_fail git -c rerere.enabled=true merge master && + test_path_is_file .git/MERGE_HEAD && + test_path_is_file .git/MERGE_MODE && + test_path_is_file .git/MERGE_MSG && + test_path_is_file .git/MERGE_RR && + git merge --quit && + test_path_is_missing .git/MERGE_HEAD && + test_path_is_missing .git/MERGE_MODE && + test_path_is_missing .git/MERGE_MSG && + test_path_is_missing .git/MERGE_RR +' + test_done