git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] notes: teach the -e option to edit messages in editor
@ 2024-10-19  0:14 Samuel Adekunle Abraham via GitGitGadget
  2024-10-19  0:38 ` brian m. carlson
                   ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: Samuel Adekunle Abraham via GitGitGadget @ 2024-10-19  0:14 UTC (permalink / raw)
  To: git; +Cc: Samuel Adekunle Abraham, Abraham Samuel Adekunle

From: Abraham Samuel Adekunle <abrahamadekunle50@gmail.com>

Notes can be added to a commit using the -m (message),
-C (copy a note from a blob object) or
-F (read the note from a file) options.
When these options are used, Git does not open an editor,
it simply takes the content provided via these options and
attaches it to the commit as a note.

Improve flexibility to fine-tune the note before finalizing it
by allowing the messages to be prefilled in the editor and editted
after the messages have been provided through -[mF].

Signed-off-by: Abraham Samuel Adekunle <abrahamadekunle50@gmail.com>
---
    [Outreachy][RFC/PATCH] notes: teach the -e option to edit messages in
    editor
    
    Notes can be added to a commit using the -m (message), -C (copy a note
    from a blob object) or -F (read the note from a file) options. When
    these options are used, Git does not open an editor, it simply takes the
    content provided via these options and attaches it to the commit as a
    note.
    
    Improve flexibility to fine-tune the note before finalizing it by
    allowing the messages to be prefilled in the editor and edited after
    they have been provided through -[mF].

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1817%2Fdevdekunle%2Fnotes_add_e_option-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1817/devdekunle/notes_add_e_option-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1817

 builtin/notes.c  |  4 ++++
 t/t3301-notes.sh | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/builtin/notes.c b/builtin/notes.c
index 8c26e455269..02cdfdf1c9d 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -489,6 +489,8 @@ static int add(int argc, const char **argv, const char *prefix)
 		OPT_CALLBACK_F('c', "reedit-message", &d, N_("object"),
 			N_("reuse and edit specified note object"), PARSE_OPT_NONEG,
 			parse_reedit_arg),
+		OPT_BOOL('e', "edit", &d.use_editor,
+			N_("edit note message in editor")),
 		OPT_CALLBACK_F('C', "reuse-message", &d, N_("object"),
 			N_("reuse specified note object"), PARSE_OPT_NONEG,
 			parse_reuse_arg),
@@ -667,6 +669,8 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 		OPT_CALLBACK_F('C', "reuse-message", &d, N_("object"),
 			N_("reuse specified note object"), PARSE_OPT_NONEG,
 			parse_reuse_arg),
+		OPT_BOOL('e', "edit", &d.use_editor,
+			N_("edit note message in editor")),
 		OPT_BOOL(0, "allow-empty", &allow_empty,
 			N_("allow storing empty note")),
 		OPT_CALLBACK_F(0, "separator", &separator,
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 99137fb2357..7f45a324faa 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1567,4 +1567,33 @@ test_expect_success 'empty notes do not invoke the editor' '
 	git notes remove HEAD
 '
 
+test_expect_success '"git notes add" with -m/-F invokes the editor with -e' '
+	test_commit 19th &&
+	GIT_EDITOR="true" git notes add -m "note message" -e &&
+	git notes remove HEAD &&
+	echo "message from file" >file_1 &&
+	GIT_EDITOR="true" git notes add -F file_1 -e &&
+	git notes remove HEAD
+'
+
+test_expect_success 'git notes append with -m/-F invokes editor with -e' '
+	test_commit 20th &&
+	GIT_EDITOR="true" git notes add -m "initial note" -e &&
+	GIT_EDITOR="true" git notes append -m "appended note" -e &&
+	git notes remove HEAD &&
+	echo  "initial note" >note_a &&
+	echo "appended note" >note_b &&
+	GIT_EDITOR="true" git notes add -F note_a -e &&
+	GIT_EDITOR="true" git notes append -F note_b -e &&
+	git notes remove HEAD
+'
+
+test_expect_success 'append note with multiple combinations of -m, -F and -e, invokes editor' '
+	test_commit 21st &&
+	echo "foo-file-1" >note_1 &&
+	echo "foo-file-2" >note_2 &&
+	GIT_EDITOR="true" git notes append -F note_1 -m "message-1" -F note_2 -m "message-2" -e &&
+	git notes remove HEAD
+'
+
 test_done

base-commit: 15030f9556f545b167b1879b877a5d780252dc16
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2024-10-23 16:51 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-19  0:14 [PATCH] notes: teach the -e option to edit messages in editor Samuel Adekunle Abraham via GitGitGadget
2024-10-19  0:38 ` brian m. carlson
2024-10-19 11:03   ` Kristoffer Haugsbakk
2024-10-19 11:24     ` Samuel Abraham
2024-10-19 10:28 ` Kristoffer Haugsbakk
2024-10-19 11:19   ` Samuel Abraham
2024-10-19 11:36 ` Kristoffer Haugsbakk
2024-10-19 11:58   ` Samuel Abraham
2024-10-20  0:03 ` [PATCH v2] " Samuel Adekunle Abraham via GitGitGadget
2024-10-21 11:58   ` Patrick Steinhardt
2024-10-21 12:37     ` Samuel Abraham
2024-10-21 18:22     ` Eric Sunshine
2024-10-21 14:38   ` [PATCH v3] " Samuel Adekunle Abraham via GitGitGadget
2024-10-21 16:52     ` Taylor Blau
2024-10-21 17:12       ` Samuel Abraham
2024-10-21 18:28       ` Eric Sunshine
2024-10-21 19:52         ` Taylor Blau
2024-10-21 18:12     ` [PATCH v4] " Samuel Adekunle Abraham via GitGitGadget
2024-10-21 19:53       ` Taylor Blau
2024-10-21 21:44         ` Samuel Abraham
2024-10-23  6:14       ` Patrick Steinhardt
2024-10-23 16:51         ` Samuel Abraham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).