From patchwork Mon Sep 21 13:30:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11789897 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7CFF139A for ; Mon, 21 Sep 2020 13:31:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA2D3206A2 for ; Mon, 21 Sep 2020 13:31:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QmwWUP23" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727160AbgIUNa4 (ORCPT ); Mon, 21 Sep 2020 09:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727054AbgIUNay (ORCPT ); Mon, 21 Sep 2020 09:30:54 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0D25C0613CF for ; Mon, 21 Sep 2020 06:30:53 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id d4so12151110wmd.5 for ; Mon, 21 Sep 2020 06:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=R+cC6FXI8JE/HCt/Gv5ViqTPLA3K3/Rjz9HVYKkUuHM=; b=QmwWUP23gyoWULaoG3aurHRWPvygrFslcmEAyfGAtUiOkO7jp3YzQJsoj/IJAVUzkM lwP5Oy+jPZHzfSqs1m7Qi5W4F4Zqp5fxw6WkYajzq6qTLlMUK6KkTEOPF66vrbI/7b7R mA7vfDy1msM1tDVqWaIidq0ql9VZ1F6vnxuW7uwLDHCgZMZJfOruziOqyS2YVosPCvNY SqHNBc6MlH8AC7qu+WJb6bVbQK5qk/gh0Cf+liRHjuLI3bhYBjoxPWf47bBxuw4U1d7r 4kMznoS0QfZbpmqG855cV7IW7iTMKN3wIh2pUJO5xOT0FXxocJKVK6LeJeJv9NUIyGc7 x0bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=R+cC6FXI8JE/HCt/Gv5ViqTPLA3K3/Rjz9HVYKkUuHM=; b=DGg4f/wIzqvOFxxMh9zWIopLCCXJ3QB5Haxd5bN3IQ92SkjQpKhPl/I8l1/aEM2C2I G+eicLeReSoWQYIlSsyaNrYQ5zr+MyWhjRSNQviOZeUwku73ICgKISHe7FCMhAUUq87Y V0rF5CM71FYu0Nd8Tt8PYioxYUkpnqOPjaiU4piYSC/G4v35RbjX0KCGSzTgJ802ah49 KK77KtHuleN9y9KTszSXjLlYEBE16B9i1ohYRX4/mlhREcYwKXmfJOdnsKLPzGFfNDGb d5TNij+TYA5ngpSl+J2oHC+gtutX1wywn7EjkozS95F15X8RC1PEgqRSmbTzWcqVhqss lhrg== X-Gm-Message-State: AOAM5330BcNwD5vsfwhCNjzpbmJadBgWnHIDaFTpGIJeprhbqUL7ZdvP XHuqPxOtV0v9+ibqaZxBzRJoDJbEjqc= X-Google-Smtp-Source: ABdhPJyawpS0rV1cU84d4RGHd2WW2E40LEZbjj80lQTGFFXrfs+yjbnh6BcXY5H2ny8X7nzlQN9ycg== X-Received: by 2002:a1c:b703:: with SMTP id h3mr29481621wmf.131.1600695052332; Mon, 21 Sep 2020 06:30:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g14sm21607263wrv.25.2020.09.21.06.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 06:30:51 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Phillip Wood via GitGitGadget" Date: Mon, 21 Sep 2020 13:30:48 +0000 Subject: [PATCH 1/3] commit docs: use backquotes when quoting options Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood Make sure that option names are typeset in a monospace font. Signed-off-by: Phillip Wood --- Documentation/git-commit.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index a3baea32ae..a1d1d1246f 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -82,7 +82,7 @@ OPTIONS -c :: --reedit-message=:: - Like '-C', but with `-c` the editor is invoked, so that + Like `-C`, but with `-c` the editor is invoked, so that the user can further edit the commit message. --fixup=:: @@ -99,10 +99,10 @@ OPTIONS linkgit:git-rebase[1] for details. --reset-author:: - When used with -C/-c/--amend options, or when committing after a - conflicting cherry-pick, declare that the authorship of the - resulting commit now belongs to the committer. This also renews - the author timestamp. + When used with `-C`/`-c`/`--amend` options, or when committing + after a conflicting cherry-pick, declare that the authorship of + the resulting commit now belongs to the committer. This also + renews the author timestamp. --short:: When doing a dry-run, give the output in the short-format. See From patchwork Mon Sep 21 13:30:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11789899 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5A586CB for ; Mon, 21 Sep 2020 13:31:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 871D1206A2 for ; Mon, 21 Sep 2020 13:31:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YGNJLYhA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727049AbgIUNa4 (ORCPT ); Mon, 21 Sep 2020 09:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727078AbgIUNaz (ORCPT ); Mon, 21 Sep 2020 09:30:55 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 817B4C0613D0 for ; Mon, 21 Sep 2020 06:30:54 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id e16so12797537wrm.2 for ; Mon, 21 Sep 2020 06:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=nrzEGyk/IQsEX7tT1PW/cI2l5YyFqXkq2IZHqY66kVg=; b=YGNJLYhAQYUcBJv5mAdTBnElgMbDi5QeZ+KPos7VLuety1zzgylXfiqR8DkvoRF6dJ 6t/4OhU4+o49s271vzHFMVDiXHin7btx8xRUM+NdTVs5lUlSzKKkzrmlro3IJrbMITtj 5JfOrm0lqPTs6jFzFvVe5bJGuf1DlHxOrc4zUP8F7C3k6hVuNY+da8j5CsmSpnavmjaO xRCPtQPuXF6lvUKHp22w/lypeMXPgqOkU2hgIOQnLMAVxs4mu1qUz7DR2n9EOxOz7eKe rBhlnVBdhr5zCdJUcuMC/CwqYuv2GhoYUboPdnUVZvpgVZykm09RdutChpW64uBTQURr scbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=nrzEGyk/IQsEX7tT1PW/cI2l5YyFqXkq2IZHqY66kVg=; b=R/fEdL5aWkr7DKBjsGA4saSesV0nX2cIv50w04rqJbaVbv2PqZL1S5FCa3IUZyRvLw C8zZNqITLMZlntfYTShs6fjDSc2tYessi2KxPVvv2b3OQlP/XLgncvFt02MGhPoq6wG8 Q0coC6+rvhd++rOTgvXf7rkWFUO6AoiZsMaE4rL68A0eO/KlPdQ/gK0/ZDjGch1/TJmM GMCr9Nn5VE25PSSt99Ds+9WTq2d1jIPRZdVXRFuJtggwHxK8Wlqen4t3C8/ox8DsK0vb A0sXtuj0R1laPYG+766oFmVNku+c9j7m05U8Ts4IS1yQf0agQwaEkaaSDPUPUlYSYmbY yZEg== X-Gm-Message-State: AOAM5319/ln9jJlJ8zIZAiU0252VwVRr0NUU6lnXGKb8W0N6Dmc/Dxas 43enlsbhA+mfxUd10sseu3aBmH2Hq38= X-Google-Smtp-Source: ABdhPJxDk2kz6gokmxf3zorjW5nft2B8f8Kt7T0htHsis1YUyGhr9Jt+gy5C1mYQt/nZM81JIRsx2w== X-Received: by 2002:a5d:4a4b:: with SMTP id v11mr51669925wrs.36.1600695053174; Mon, 21 Sep 2020 06:30:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y6sm20995304wrt.80.2020.09.21.06.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 06:30:52 -0700 (PDT) Message-Id: <80a69318b57348c59e45c0f8df1c342ef84388d4.1600695050.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Phillip Wood via GitGitGadget" Date: Mon, 21 Sep 2020 13:30:49 +0000 Subject: [PATCH 2/3] commit: reorder synopsis Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood Rearrange the synopsis for `git commit` to try and put options that are used more often nearer the beginning. Signed-off-by: Phillip Wood --- Documentation/git-commit.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index a1d1d1246f..9de4dc5d66 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -8,11 +8,11 @@ git-commit - Record changes to the repository SYNOPSIS -------- [verse] -'git commit' [-a | --interactive | --patch] [-s] [-v] [-u] [--amend] - [--dry-run] [(-c | -C | --fixup | --squash) ] - [-F | -m ] [--reset-author] [--allow-empty] - [--allow-empty-message] [--no-verify] [-e] [--author=] - [--date=] [--cleanup=] [--[no-]status] +'git commit' [-a | --interactive | --patch] [--amend] + [(-c | -C | --fixup | --squash) ] [-F | -m ] + [--allow-empty] [--allow-empty-message] [--no-verify] [-e] + [--reset-author] [--author=] [--date=] + [--cleanup=] [-v] [-u] [--dry-run] [--[no-]status] [-i | -o] [--pathspec-from-file= [--pathspec-file-nul]] [-S[]] [--] [...] From patchwork Mon Sep 21 13:30:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11789895 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DD706CB for ; Mon, 21 Sep 2020 13:30:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BF0621BE5 for ; Mon, 21 Sep 2020 13:30:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E1Q5Pwz9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726749AbgIUNa5 (ORCPT ); Mon, 21 Sep 2020 09:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727062AbgIUNaz (ORCPT ); Mon, 21 Sep 2020 09:30:55 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FC77C0613D1 for ; Mon, 21 Sep 2020 06:30:55 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id b79so12691922wmb.4 for ; Mon, 21 Sep 2020 06:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=eobagORDrsVXE1P0bHoIU/4L3O/zDkcGzvNeMF+BhKs=; b=E1Q5Pwz95gJOYmnKTm4kPwjd8e+7jZGL84B454ch/eu8iKVmbEnQVqxM+Jxe3jhsdA 5qBBNQg5bvxaaSAoJntBDLKImSGna6K+CnQXI98f4VvJuambFWQvVW6unkXazEhyJ9QU HD74sOu9UBVVt2AsRHXLO1j07SH3fH+Ud3ys0WP4V5GNnA24FQ4RU5DO8ltWxKFczAvq jojNCsU1KV1vbf8ELPX1m6oYUfye9Pgrn5BXpCUULVQXE0ej/Mga2SyRHcgEr0T2AcNk UvBR1lHS3CzYoAl/BVn7Kkmby/LfhpB29Y3bTKOik05eF0NnTp7/GZViFFK6pyjO2LBE etXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=eobagORDrsVXE1P0bHoIU/4L3O/zDkcGzvNeMF+BhKs=; b=SGcwZkeouebpGiWq9hSYaNa8bY6slbia8+zGBoGq63KnuEzTNxMvf9OZIT2f2P2Eju 9L2cu7acxqXlDzOSiE0unN72my1r/ZMCdywxR4RxMjYRAio/6SumvMv8Tqpk0fIsH4QM ygNTT+NYMsmUEvH0yhudY0I51MhCgyxCL+lybmBHqA653U1H1+bAXYedb9mUlWUfP590 aJ5O3sEebg3J4WVdLOUWxTr4onsP0/K4kA/ajnTA8Q6P1dKZc0hrkI8IoETttyOqvitO yZo80KrXU/jpSFiOrwuYKtlc2zK7999HM2a/T2OPm9nVgDJdC7kocN8TJrxrH/FkXGL4 5Ppw== X-Gm-Message-State: AOAM5330DcH4Gna7Z+YNZ94Arwj3Yo2v36AVG3u8oEaSv4ajrnsS1ssG +UGKPgaM4ImtXBAg+F/MI5ZVkR5qvr0= X-Google-Smtp-Source: ABdhPJzQs3OXZ9T0DPB3qeLva6AvhCt+a0g4usImFmPjG4sqCtLg8zQFe32vuM8MCLW1Il8ahNXRfg== X-Received: by 2002:a1c:7e15:: with SMTP id z21mr29952373wmc.21.1600695053904; Mon, 21 Sep 2020 06:30:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u17sm19284160wmm.4.2020.09.21.06.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 06:30:53 -0700 (PDT) Message-Id: <7f851e7c20aafdae5d5ae46ee1083b32ecc82c84.1600695050.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Phillip Wood via GitGitGadget" Date: Mon, 21 Sep 2020 13:30:50 +0000 Subject: [PATCH 3/3] commit: add an option the reword HEAD Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood If one notices a typo in the last commit after starting to stage changes for the next commit it is useful to be able to reword the last commit without changing its contents. Currently the way to do that is by specifying --amend --only with no pathspec which is not that obvious to new users (so much so that before beb635ca9c ("commit: remove 'Clever' message for --only --amend", 2016-12-09) commit printed a message to congratulate the user on figuring out how to do it). If the last commit is empty one has to pass --allow-empty as well even though the contents are not being changed. This commits adds a --reword option for commit that rewords the last commit without changing its contents. Signed-off-by: Phillip Wood --- Documentation/git-commit.txt | 14 ++++++- builtin/commit.c | 46 +++++++++++++++++++++- t/t7501-commit-basic-functionality.sh | 56 +++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 3 deletions(-) diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 9de4dc5d66..8ec87ecb6b 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -8,7 +8,7 @@ git-commit - Record changes to the repository SYNOPSIS -------- [verse] -'git commit' [-a | --interactive | --patch] [--amend] +'git commit' [-a | --interactive | --patch] [--amend | --reword] [(-c | -C | --fixup | --squash) ] [-F | -m ] [--allow-empty] [--allow-empty-message] [--no-verify] [-e] [--reset-author] [--author=] [--date=] @@ -99,7 +99,7 @@ OPTIONS linkgit:git-rebase[1] for details. --reset-author:: - When used with `-C`/`-c`/`--amend` options, or when committing + When used with `-C`/`-c`/`--amend`/`--reword` options, or when committing after a conflicting cherry-pick, declare that the authorship of the resulting commit now belongs to the committer. This also renews the author timestamp. @@ -229,6 +229,16 @@ variable (see linkgit:git-config[1]). For example, `git commit --amend --no-edit` amends a commit without changing its commit message. +--reword:: + Reword the commit message of the tip of the current branch by + replacing it with a new commit. The commit contents will be + unchanged even if there are staged changes. This is equivalent + to specifying `--amend --only --allow-empty` with no paths. ++ +You should understand the implications of rewriting history if you +reword a commit that has already been published. (See the "RECOVERING +FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].) + --amend:: Replace the tip of the current branch by creating a new commit. The recorded tree is prepared as usual (including diff --git a/builtin/commit.c b/builtin/commit.c index 5d91b13a5c..f7913f771a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -107,6 +107,7 @@ static const char *author_message, *author_message_buffer; static char *edit_message, *use_message; static char *fixup_message, *squash_message; static int all, also, interactive, patch_interactive, only, amend, signoff; +static int reword; static int edit_flag = -1; /* unspecified */ static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship; static int config_commit_verbose = -1; /* unspecified */ @@ -1152,6 +1153,41 @@ static void finalize_deferred_config(struct wt_status *s) s->ahead_behind_flags = AHEAD_BEHIND_FULL; } +static void validate_reword_options(int argc, struct commit *current_head) +{ + if (!current_head) + die(_("You have nothing to reword.")); + if (whence != FROM_COMMIT) { + if (whence == FROM_MERGE) + die(_("You are in the middle of a merge -- cannot " + "reword.")); + else if (is_from_cherry_pick(whence)) + die(_("You are in the middle of a cherry-pick -- cannot" + " reword.")); + else if (is_from_rebase(whence)) + die(_("You are in the middle of a rebase -- cannot " + "reword.")); + } + if (amend) + die(_("cannot combine --reword with --amend")); + if (argc) + die(_("cannot combine --reword with paths")); + if (interactive) + die(_("cannot combine --reword with --interactive")); + if (patch_interactive) + die(_("cannot combine --reword with --patch")); + if (all) + die(_("cannot combine --reword with --all")); + if (also) + die(_("cannot combine --reword with --include")); + if (only) + die(_("cannot combine --reword with --only")); + if (!edit_flag && !force_author && !force_date && !renew_authorship && + !use_message && !edit_message && !fixup_message && + !squash_message && !logfile && !have_option_m && !signoff) + die(_("cannot combine --reword with --no-edit")); +} + static int parse_and_validate_options(int argc, const char *argv[], const struct option *options, const char * const usage[], @@ -1186,6 +1222,12 @@ static int parse_and_validate_options(int argc, const char *argv[], else if (whence == FROM_REBASE_PICK) die(_("You are in the middle of a rebase -- cannot amend.")); } + if (reword) { + validate_reword_options(argc, current_head); + amend = 1; + only = 1; + allow_empty = 1; + } if (fixup_message && squash_message) die(_("Options --squash and --fixup cannot be used together")); if (use_message) @@ -1208,7 +1250,8 @@ static int parse_and_validate_options(int argc, const char *argv[], use_message = "HEAD"; if (!use_message && !is_from_cherry_pick(whence) && !is_from_rebase(whence) && renew_authorship) - die(_("--reset-author can be used only with -C, -c or --amend.")); + die(_("--reset-author can be used only with -C, -c, --amend " + "or --reword.")); if (use_message) { use_message_buffer = read_commit_message(use_message); if (!renew_authorship) { @@ -1537,6 +1580,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) OPT_BOOL('z', "null", &s.null_termination, N_("terminate entries with NUL")), OPT_BOOL(0, "amend", &amend, N_("amend previous commit")), + OPT_BOOL(0, "reword", &reword, N_("reword the previous commit")), OPT_BOOL(0, "no-post-rewrite", &no_post_rewrite, N_("bypass post-rewrite hook")), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, N_("mode"), N_("show untracked files, optional modes: all, normal, no. (Default: all)"), PARSE_OPT_OPTARG, NULL, (intptr_t)"all" }, OPT_PATHSPEC_FROM_FILE(&pathspec_from_file), diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index 110b4bf459..1ea65b426a 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -713,4 +713,60 @@ test_expect_success '--dry-run --short' ' git commit --dry-run --short ' +test_expect_success '--reword does not commit staged changes' ' + echo changed >file && + git add file && + cat >expect <<-EOF && + $(git log -1 --pretty=format:%B HEAD) + + reworded + EOF + GIT_EDITOR="printf reworded >>" git commit --reword && + git log -1 --pretty=format:%B >actual && + test_cmp expect actual && + test_cmp_rev HEAD@{1}^{tree} HEAD^{tree} && + test_cmp_rev HEAD@{1}^ HEAD^ && + git cat-file blob :file >actual && + test_cmp file actual +' + +test_reword_opt () { + test_expect_success C_LOCALE_OUTPUT "--reword incompatible with $1" " + echo 'fatal: cannot combine --reword with $1' >expect && + test_must_fail git commit --reword $1 2>actual && + test_cmp expect actual + " +} + +for opt in --all --amend --include --interactive --only --patch --no-edit +do + test_reword_opt $opt +done + +test_expect_success C_LOCALE_OUTPUT '--reword with paths' ' + echo "fatal: cannot combine --reword with paths" >expect && + test_must_fail git commit --reword file 2>actual && + test_cmp expect actual +' + +test_reword_no_edit () { + test_expect_success "--reword $@ --no-edit" ' + git commit --reword '"$@"' --no-edit + ' +} + +for opt in -mmessage -CHEAD^ -cHEAD --reset-author \ + "--author=\"Commit Author \"" \ + --date=yesterday --fixup=HEAD^ --squash=HEAD^ --signoff +do + test_reword_no_edit "$opt" +done + +test_expect_success '--reword -F' ' + echo reworded >msg && + git commit --reword -F msg --no-edit && + git log -1 --pretty=format:%B >actual && + test_cmp msg actual +' + test_done