[PATCH v2 3/4] notes: refuse to edit non-blobs
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/notes.c | 6 ++++--
t/t3301-notes.sh | 4 ++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 2960535..44fb8b6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -109,12 +109,14 @@ static int list_each_note(const unsigned char *object_sha1,
return 0;
}
-static void write_note_data(int fd, const unsigned char *sha1)
+static void write_note_blob(int fd, const unsigned char *sha1)
{
unsigned long size;
enum object_type type;
char *buf = read_sha1_file(sha1, &type, &size);
if (buf) {
+ if (type != OBJ_BLOB)
+ die(_("note %s is not a blob"), sha1_to_hex(sha1));
if (size)
write_or_die(fd, buf, size);
free(buf);
@@ -178,7 +180,7 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
if (msg->given)
write_or_die(fd, msg->buf.buf, msg->buf.len);
else if (prev && !append_only)
- write_note_data(fd, prev);
+ write_note_blob(fd, prev);
write_or_die(fd, note_template, strlen(note_template));
write_commented_object(fd, object);
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index dd8675f..66cc872 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1236,4 +1236,8 @@ test_expect_success 'non-blobs notes are shown in human-readable form' '
test_cmp expected actual
'
+test_expect_success 'cannot edit non-blob notes' '
+ test_must_fail git notes edit
+'
+
test_done
--
1.7.3.1.256.g2539c.dirty