notes: do not trigger editor when adding an empty note
commit8b426c84f376657e1e10839f3f5dafd9ba99593d
authorDavid Disseldorp <ddiss@suse.de>
Mon, 29 Jul 2024 15:14:00 +0000 (29 17:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Jul 2024 22:31:30 +0000 (29 15:31 -0700)
tree4448823eabf18b01a060808ddf71a7ed15ef95c3
parent39bf06adf96da25b87c9aa7d35a32ef3683eb4a4
notes: do not trigger editor when adding an empty note

With "git notes add -C $blob", the given blob contents are to be made
into a note without involving an editor.  But when "--allow-empty" is
given, the editor is invoked, which can cause problems for
non-interactive callers[1].

This behaviour started with 90bc19b3ae (notes.c: introduce
'--separator=<paragraph-break>' option, 2023-05-27), which changed
editor invocation logic to check for a zero length note_data buffer.

Restore the original behaviour of "git note" that takes the contents
given via the "-m", "-C", "-F" options without invoking an editor, by
checking for any prior parameter callbacks, indicated by a non-zero
note_data.msg_nr.  Remove the now-unneeded note_data.given flag.

Add a test for this regression by checking whether GIT_EDITOR is
invoked alongside "git notes add -C $empty_blob --allow-empty"

[1] https://github.com/ddiss/icyci/issues/12

Signed-off-by: David Disseldorp <ddiss@suse.de>
[jc: enhanced the test with -m/-F options]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/notes.c
t/t3301-notes.sh