Skip to content

Commit

Permalink
notes: teach the -e option to edit messages in editor
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
devdekunle committed Oct 18, 2024
1 parent 15030f9 commit 61a6d2d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions builtin/notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions t/t3301-notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 61a6d2d

Please sign in to comment.