Teach builtin-notes to remove empty notes
When the result of editing a note is an empty string, the associated note entry should be deleted from the notes tree. This allows deleting notes by invoking either "git notes -m ''" or "git notes -F /dev/null". Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
851c2b3791
commit
a0b4dfa9b3
|
@ -113,7 +113,7 @@ static void create_note(const unsigned char *object,
|
||||||
|
|
||||||
stripspace(buf, 1);
|
stripspace(buf, 1);
|
||||||
|
|
||||||
if (!skip_editor && !buf->len) {
|
if (!buf->len) {
|
||||||
fprintf(stderr, "Removing note for object %s\n",
|
fprintf(stderr, "Removing note for object %s\n",
|
||||||
sha1_to_hex(object));
|
sha1_to_hex(object));
|
||||||
hashclr(result);
|
hashclr(result);
|
||||||
|
@ -197,7 +197,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
|
||||||
struct notes_tree *t;
|
struct notes_tree *t;
|
||||||
unsigned char object[20], new_note[20];
|
unsigned char object[20], new_note[20];
|
||||||
const unsigned char *note;
|
const unsigned char *note;
|
||||||
const char *object_ref;
|
const char *object_ref, *logmsg;
|
||||||
|
|
||||||
int edit = 0, show = 0;
|
int edit = 0, show = 0;
|
||||||
const char *msgfile = NULL;
|
const char *msgfile = NULL;
|
||||||
struct msg_arg msg = { 0, STRBUF_INIT };
|
struct msg_arg msg = { 0, STRBUF_INIT };
|
||||||
|
@ -271,8 +272,14 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
create_note(object, &buf, msg.given || msgfile, note, new_note);
|
create_note(object, &buf, msg.given || msgfile, note, new_note);
|
||||||
|
if (is_null_sha1(new_note)) {
|
||||||
|
remove_note(t, object);
|
||||||
|
logmsg = "Note removed by 'git notes edit'";
|
||||||
|
} else {
|
||||||
add_note(t, object, new_note, combine_notes_overwrite);
|
add_note(t, object, new_note, combine_notes_overwrite);
|
||||||
commit_notes(t, "Note added by 'git notes edit'");
|
logmsg = "Note added by 'git notes edit'";
|
||||||
|
}
|
||||||
|
commit_notes(t, logmsg);
|
||||||
|
|
||||||
free_notes(t);
|
free_notes(t);
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
|
|
|
@ -234,6 +234,37 @@ test_expect_success 'show -m notes' '
|
||||||
test_cmp expect-m output
|
test_cmp expect-m output
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'remove note with -F /dev/null (setup)' '
|
||||||
|
git notes edit -F /dev/null
|
||||||
|
'
|
||||||
|
|
||||||
|
cat > expect-rm-F << EOF
|
||||||
|
commit bd1753200303d0a0344be813e504253b3d98e74d
|
||||||
|
Author: A U Thor <author@example.com>
|
||||||
|
Date: Thu Apr 7 15:17:13 2005 -0700
|
||||||
|
|
||||||
|
5th
|
||||||
|
EOF
|
||||||
|
|
||||||
|
printf "\n" >> expect-rm-F
|
||||||
|
cat expect-F >> expect-rm-F
|
||||||
|
|
||||||
|
test_expect_success 'verify note removal with -F /dev/null' '
|
||||||
|
git log -4 > output &&
|
||||||
|
test_cmp expect-rm-F output &&
|
||||||
|
! git notes show
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'do not create empty note with -m "" (setup)' '
|
||||||
|
git notes edit -m ""
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'verify non-creation of note with -m ""' '
|
||||||
|
git log -4 > output &&
|
||||||
|
test_cmp expect-rm-F output &&
|
||||||
|
! git notes show
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'create other note on a different notes ref (setup)' '
|
test_expect_success 'create other note on a different notes ref (setup)' '
|
||||||
: > a6 &&
|
: > a6 &&
|
||||||
git add a6 &&
|
git add a6 &&
|
||||||
|
|
Loading…
Reference in New Issue