Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Documentation/git-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ SYNOPSIS
--------
[verse]
'git notes' [list [<object>]]
'git notes' add [-f] [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
'git notes' add [-f] [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [-e] [<object>]
'git notes' copy [-f] ( --stdin | <from-object> [<to-object>] )
'git notes' append [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
'git notes' append [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [-e] [<object>]
'git notes' edit [--allow-empty] [<object>] [--[no-]stripspace]
'git notes' show [<object>]
'git notes' merge [-v | -q] [-s <strategy> ] <notes-ref>
Expand Down Expand Up @@ -67,7 +67,9 @@ add::
the existing notes will be opened in the editor (like the `edit`
subcommand). If you specify multiple `-m` and `-F`, a blank
line will be inserted between the messages. Use the `--separator`
option to insert other delimiters.
option to insert other delimiters. You can use `-e` to edit and
fine-tune the message(s) supplied from `-m` and `-F` options
interactively (using an editor) before adding the note.

copy::
Copy the notes for the first object onto the second object (defaults to
Expand All @@ -93,6 +95,8 @@ append::
an existing note, a blank line is added before each new
message as an inter-paragraph separator. The separator can
be customized with the `--separator` option.
Edit the notes to be appended given by `-m` and `-F` options with
`-e` interactively (using an editor) before appending the note.

edit::
Edit the notes for a given object (defaults to HEAD).
Expand Down
8 changes: 6 additions & 2 deletions builtin/notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
static const char *separator = "\n";
static const char * const git_notes_usage[] = {
N_("git notes [--ref <notes-ref>] [list [<object>]]"),
N_("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
N_("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>] [-e]"),
N_("git notes [--ref <notes-ref>] copy [-f] <from-object> <to-object>"),
N_("git notes [--ref <notes-ref>] append [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
N_("git notes [--ref <notes-ref>] append [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>] [-e]"),
N_("git notes [--ref <notes-ref>] edit [--allow-empty] [<object>]"),
N_("git notes [--ref <notes-ref>] show [<object>]"),
N_("git notes [--ref <notes-ref>] merge [-v | -q] [-s <strategy>] <notes-ref>"),
Expand Down 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
63 changes: 63 additions & 0 deletions t/t3301-notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1567,4 +1567,67 @@ test_expect_success 'empty notes do not invoke the editor' '
git notes remove HEAD
'

test_expect_success 'git notes add with -m/-F invokes editor with -e' '
test_commit 19th &&
echo "edited" >expect &&
MSG="$(cat expect)" git notes add -m "initial" -e &&
git notes show >actual &&
test_cmp expect actual &&
git notes remove HEAD &&

# Add a note using -F and edit it
echo "initial" >note_file &&
MSG="$(cat expect)" git notes add -F note_file -e &&
git notes show >actual &&
test_cmp expect actual
'

test_expect_success 'git notes append with -m/-F invokes the editor with -e' '
test_commit 20th &&
cat >expect <<-EOF &&
initial

edited
EOF
git notes add -m "initial" &&
MSG="edited" git notes append -m "appended" -e &&

# Verify the note content was appended and edited
git notes show >actual &&
test_cmp expect actual &&
git notes remove HEAD &&

# Append a note using -F and edit it
echo "note from file" >note_file &&
git notes add -m "initial" &&
MSG="edited" git notes append -F note_file -e &&

# Verify notes from file has been edited in editor and appended
git notes show >actual &&
test_cmp expect actual
'

test_expect_success 'git notes with a combination of -m, -F and -e invokes editor' '
test_commit 21st &&
echo "foo-file-1" >note_1 &&
echo "foo-file-2" >note_2 &&
echo "edited" >expect &&

MSG=$(cat expect) git notes append -F note_1 -m "message-1" -F note_2 -e &&

# Verify that combined messages from file and -m have been edited
git notes show >actual &&
test_cmp expect actual
'
test_expect_success 'git notes append aborts when editor fails with -e' '
test_commit 22nd &&
echo "foo-file-1" >note_1 &&

# Try to append a note with -F and -e, but make the editor fail
test_env GIT_EDITOR="false" test_must_fail git notes append -F note_1 -e &&

# Verify that no note was added due to editor failure
test_must_fail git notes show
'

test_done
Loading