From patchwork Sun May 14 13:17:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristoffer Haugsbakk X-Patchwork-Id: 13240458 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB52FC77B7F for ; Sun, 14 May 2023 13:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232116AbjENNUK (ORCPT ); Sun, 14 May 2023 09:20:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbjENNUI (ORCPT ); Sun, 14 May 2023 09:20:08 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 740FC1FD4 for ; Sun, 14 May 2023 06:20:07 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id E0E175C012B; Sun, 14 May 2023 09:20:06 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 14 May 2023 09:20:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=khaugsbakk.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1684070406; x= 1684156806; bh=JI6vZgbZZPEcAo+aOqFg/6CzsHu3ixXozB03mY1TNXE=; b=j b9N3kEXqVvu1EXAsMtgaaZlOeV77OiCgXacGwSNkgsBawAGZaLwbMBwZx+zYL2j+ UKtl/MJb3r9d5EqXyJ8Y7u44V43eiKbX09Nig+39z60e88Zz2nolm/uxQcvPQazN 8zRei8DPhVVKeLI1Q0HtSFq133os9AOjVaBA3xrXzKLiFvFztxcD6IejziCzbgd2 HLQ5CcMVBItcih3UBgLXfX/dOMuf8hKxCYPWVUNQjJynQDEGtKu1NnuUjpWTkZmN 4u06pOALsM4KyzcJmbDoAP3xGC8eQ66PLrDCenRnkkr2so+1m0CpzcS1yXWAtA6U uJv5zlLh/WrFDM57Kdxww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1684070406; x= 1684156806; bh=JI6vZgbZZPEcAo+aOqFg/6CzsHu3ixXozB03mY1TNXE=; b=E zwBDVM6qvrPI4bU5w91bbhjJ1wOFHq75LJGqPafmU23c/ffIocGXPw/hMIhWZvmn N7qgQcChnfHCCQTvh6W0J7bphZzDbpZWOEXYr65xlUknUdCxv6ryQgRkxZKqJGZx SUUp/tSYnf7ncLwUQu3Tm/2XkIJhgMDGnGEsFFon8fQcWEEz+b9qYvbbk1FPYJ+b JW1LayiQDRQCjU0n3ss0GmggXJ+Up0luKdbao0d6NA1t9yCNsWtoJ/NNbgb38FwV kDbr6XUojggNpibenC3p1yYfHiP/4xZ4pPJI1pnYJflz9SMUwVafs3LYNxYnZqoo qA8dgmVY1upqZfSUreokg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehhedgieegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefmrhhishhtohhffhgvrhcujfgruhhgshgsrghkkhcuoegt ohguvgeskhhhrghughhssggrkhhkrdhnrghmvgeqnecuggftrfgrthhtvghrnhepteduie ehgedutdfgudevkefhveduieeiteejhfffteeitdegjeeihedthfejgfetnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheptghouggvsehkhhgruh hgshgsrghkkhdrnhgrmhgv X-ME-Proxy: Feedback-ID: i2671468f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 14 May 2023 09:20:05 -0400 (EDT) From: Kristoffer Haugsbakk To: git@vger.kernel.org Cc: peff@peff.net, Kristoffer Haugsbakk Subject: [PATCH 1/3] t/t7004-tag: add regression test for existing behavior Date: Sun, 14 May 2023 15:17:58 +0200 Message-Id: <87b709d856d8f788a2a50a2804ac508d5775f324.1684067644.git.code@khaugsbakk.name> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The standard tag message file is unlinked if the tag is created. Signed-off-by: Kristoffer Haugsbakk --- Notes (series): `test_when_finished` because this test interferes with the next one without it. t/t7004-tag.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index 9aa1660651..550b5b1cce 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -2127,4 +2127,13 @@ test_expect_success 'Does --[no-]contains stop at commits? Yes!' ' test_cmp expected actual ' +test_expect_success 'If tag is created then tag message file is unlinked' ' + test_when_finished "git tag -d foo" && + write_script fakeeditor <<-\EOF && + echo Message >.git/TAG_EDITMSG + EOF + GIT_EDITOR=./fakeeditor git tag -a foo && + ! test -e .git/TAG_EDITMSG +' + test_done From patchwork Sun May 14 13:17:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristoffer Haugsbakk X-Patchwork-Id: 13240459 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30DFAC77B7F for ; Sun, 14 May 2023 13:20:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229526AbjENNUU (ORCPT ); Sun, 14 May 2023 09:20:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjENNUP (ORCPT ); Sun, 14 May 2023 09:20:15 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF80430CF for ; Sun, 14 May 2023 06:20:13 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 682C65C004F; Sun, 14 May 2023 09:20:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 14 May 2023 09:20:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=khaugsbakk.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1684070413; x= 1684156813; bh=YHjumG4EiDCYjprOGjGIvdEhPPNL9JilF0ifu7WYFAQ=; b=J ofL0ed8QKgSYSt9TG8w0l0FOAfEbbmQUbkog5MYiHz89azOMGxY42TAun8n294we sZAMMLmhQs1H7mXfvZMQvEP2AO2rXkhHPkjPQ1ehmwz8X0CL22DKbCpqgU0D2cpy XmtZOS/jbGoiWf9eykM7MvOxDs3UwJFIZKIabLIuIhBxkXNGxq1tnEFr4JBBBhN5 JSydB+QhGF66fPlBZK9uT7YvyObYbUN3pjX+NRUfhH6JPEObId7+nMJ7kP5IriB8 0Sj1+5+4u3t+3M2inJHjZCslqY2eKdYVbzuJrQM2ZgP40PiCHZ2JhZQZRUK628+9 uoiqBtvepjeAkXvL0apqQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1684070413; x= 1684156813; bh=YHjumG4EiDCYjprOGjGIvdEhPPNL9JilF0ifu7WYFAQ=; b=I afWpwlmg90i1rgHn0cmUCMJqiyh5mDlC4r2D5vNh3pbDEGZdocK1ujJ+YLrCZXvR YpmI/89fo/VC5jFSeRPk95dHorW75c1xijfYoiHhoLxPraB46XrWqWvUXXqEdsh8 Pzr2XjyrIMei51A/eMjr7SObVH8OC9c6QpN7ox4LW+pIshqvhehhiBGCI+4SfP0r JkwZvD3E5rTOABfMPdkh7PyJgG23bYx89ocJaNhxUlsfEeh4JlodC2vjwxq73nB8 sQ3DOmd6Lu/s3inhLIrZeFhh3z/ePtbBwUUMxzZ+/fOajbDg2w+3B/7y3EH3V+h7 ylU8AUn4fUutOAYKW2/kw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehhedgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefmrhhishhtohhffhgvrhcujfgruhhgshgsrghkkhcuoegt ohguvgeskhhhrghughhssggrkhhkrdhnrghmvgeqnecuggftrfgrthhtvghrnhepteduie ehgedutdfgudevkefhveduieeiteejhfffteeitdegjeeihedthfejgfetnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheptghouggvsehkhhgruh hgshgsrghkkhdrnhgrmhgv X-ME-Proxy: Feedback-ID: i2671468f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 14 May 2023 09:20:12 -0400 (EDT) From: Kristoffer Haugsbakk To: git@vger.kernel.org Cc: peff@peff.net, Kristoffer Haugsbakk Subject: [PATCH 2/3] t/t7004-tag: add failing tag message file test Date: Sun, 14 May 2023 15:17:59 +0200 Message-Id: <1f24aa43f70b16381ef0cfb4f1d482706161554d.1684067644.git.code@khaugsbakk.name> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Kristoffer Haugsbakk --- t/t7004-tag.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index 550b5b1cce..1e512dbe06 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -2136,4 +2136,14 @@ test_expect_success 'If tag is created then tag message file is unlinked' ' ! test -e .git/TAG_EDITMSG ' +test_expect_success 'If tag cannot be created then tag message file is not unlinked' ' + test_when_finished "git tag -d foo/bar" && + write_script fakeeditor <<-\EOF && + echo Message >.git/TAG_EDITMSG + EOF + git tag foo/bar && + ! GIT_EDITOR=./fakeeditor git tag -a foo && + test -e .git/TAG_EDITMSG +' + test_done From patchwork Sun May 14 13:18:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristoffer Haugsbakk X-Patchwork-Id: 13240460 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F5C9C7EE22 for ; Sun, 14 May 2023 13:20:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237221AbjENNUW (ORCPT ); Sun, 14 May 2023 09:20:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233311AbjENNUR (ORCPT ); Sun, 14 May 2023 09:20:17 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E91882D48 for ; Sun, 14 May 2023 06:20:15 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 623145C0075; Sun, 14 May 2023 09:20:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 14 May 2023 09:20:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=khaugsbakk.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1684070415; x= 1684156815; bh=10NzY3raI+Scjpw7pySJ9k4C4P260Yu1s4xB62S8ewo=; b=Y h23bDaqWZ8cDmS82wQiKcr9mklvp2yQRbZJUVAwNERTjlLoduIACc0PF7S4pgYbX rokT9925ifuNMlKBaH1fx+jM5N284CbHHu/Me5unpw0/mfXMwM5Xf3fs5AGl3JiJ ORQ/EgX/d8tCAJMeHSl1B8qIYSnWhCL7CiQ5IjHN8pg/tjBThM9ihcW+QL6XHPUg 3jrp+0tGWJPVFMhitqmbvE9To6wrwlk+nzv3QU1BpusFRBfS00QGJ/usGI1eBH7B tgcBhrJJVR0itV3v+Po+FM5Gr+D4nx1K5HwyUIyY4T0L2kOgCbn22MK1tMlUZoYb WT/5dic5eFHEaQKiHZ/7A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1684070415; x= 1684156815; bh=10NzY3raI+Scjpw7pySJ9k4C4P260Yu1s4xB62S8ewo=; b=K HMUPUx5loOn77XxTgkYVTVIRqSOJQvcMkkIioJkIF+WpgROPprQL+zyfThK9D8hw qDB1P7EW8ndkDgMYhxdH6elKtxJS6eJs1am4f+N8rtUfYUdZrSgt9AhXVr1Ptk3Q er0h3wB0if49QMqEtCavn6GH4sik/T48A+YlZJ+YU4bKAwma0O4B9F5QbEjBgN0T fEm8uWD7XEx1WCB0x782SgHeB7QEVWPmtsUMMVY5NtW2uYt/jfGLsu5hO9BrxPF2 zRuFZnJBT4tLfCvLLKzNvJcC46SSdtCGBtBx+1oHDgqN2XsKWFmrqA+8rFuq6F8j Te8s/tmNawnsS6OnqsXNQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehhedgieegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefmrhhishhtohhffhgvrhcujfgruhhgshgsrghkkhcuoegt ohguvgeskhhhrghughhssggrkhhkrdhnrghmvgeqnecuggftrfgrthhtvghrnhepteduie ehgedutdfgudevkefhveduieeiteejhfffteeitdegjeeihedthfejgfetnecuvehluhhs thgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomheptghouggvsehkhhgruh hgshgsrghkkhdrnhgrmhgv X-ME-Proxy: Feedback-ID: i2671468f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 14 May 2023 09:20:14 -0400 (EDT) From: Kristoffer Haugsbakk To: git@vger.kernel.org Cc: peff@peff.net, Kristoffer Haugsbakk Subject: [PATCH 3/3] tag: keep the message file in case ref transaction fails Date: Sun, 14 May 2023 15:18:00 +0200 Message-Id: <999af290af4c6850aa3faa2cc95adbac3b7a3984.1684067644.git.code@khaugsbakk.name> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The ref transaction can fail after the user has written their tag message. In particular, if there exists a tag `foo/bar` and `git tag -a foo` is said then the command will only fail once it tries to write `refs/tags/foo`, which is after one has closed the editor. Hold on to the message file for a little longer so that it is not unlinked before the fatal error occurs. Signed-off-by: Kristoffer Haugsbakk --- Notes (series): I tried to maintain the proper formatting by using `clang-format` via Emacs on the affected lines. builtin/tag.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/builtin/tag.c b/builtin/tag.c index d428c45dc8..7df9c143ac 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -266,11 +266,10 @@ static const char message_advice_nested_tag[] = static void create_tag(const struct object_id *object, const char *object_ref, const char *tag, struct strbuf *buf, struct create_tag_options *opt, - struct object_id *prev, struct object_id *result) + struct object_id *prev, struct object_id *result, char *path) { enum object_type type; struct strbuf header = STRBUF_INIT; - char *path = NULL; type = oid_object_info(the_repository, object, NULL); if (type <= OBJ_NONE) @@ -294,7 +293,6 @@ static void create_tag(const struct object_id *object, const char *object_ref, int fd; /* write the template message before editing: */ - path = git_pathdup("TAG_EDITMSG"); fd = xopen(path, O_CREAT | O_TRUNC | O_WRONLY, 0600); if (opt->message_given) { @@ -336,10 +334,6 @@ static void create_tag(const struct object_id *object, const char *object_ref, path); exit(128); } - if (path) { - unlink_or_warn(path); - free(path); - } } static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb) @@ -487,6 +481,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) }; int ret = 0; const char *only_in_list = NULL; + char *path = NULL; setup_ref_filter_porcelain_msg(); @@ -621,7 +616,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix) if (create_tag_object) { if (force_sign_annotate && !annotate) opt.sign = 1; - create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object); + path = git_pathdup("TAG_EDITMSG"); + create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object, + path); } transaction = ref_transaction_begin(&err); @@ -629,8 +626,17 @@ int cmd_tag(int argc, const char **argv, const char *prefix) ref_transaction_update(transaction, ref.buf, &object, &prev, create_reflog ? REF_FORCE_CREATE_REFLOG : 0, reflog_msg.buf, &err) || - ref_transaction_commit(transaction, &err)) + ref_transaction_commit(transaction, &err)) { + if (path) + fprintf(stderr, + _("The tag message has been left in %s\n"), + path); die("%s", err.buf); + } + if (path) { + unlink_or_warn(path); + free(path); + } ref_transaction_free(transaction); if (force && !is_null_oid(&prev) && !oideq(&prev, &object)) printf(_("Updated tag '%s' (was %s)\n"), tag,