summaryrefslogtreecommitdiff
path: root/builtin/notes.c
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2011-03-30 02:02:55 +0200
committerJunio C Hamano <gitster@pobox.com>2011-03-30 13:13:52 -0700
commit84a7e35eea97388ba5ca458808119650818c2fd2 (patch)
tree718a121d0a748234fa3c79732733e73fd88185cb /builtin/notes.c
parent537d99033749591245ddd36f7317fd6b8555d803 (diff)
downloadgit-84a7e35eea97388ba5ca458808119650818c2fd2.tar.gz
Make "git notes add" more user-friendly when there are existing notes
Currently, "notes add" (without -f/--force) will abort when the given object already has existing notes. This makes sense for the modes of "git notes add" that would necessarily overwrite the old message (when using the -m/-F/-C/-c options). However, when no options are given (meaning the notes are created from scratch in the editor) it is not very user-friendly to abort on existing notes, and forcing the user to run "git notes edit". Instead, it is better to simply "redirect" to "git notes edit" automatically, i.e. open the existing notes in the editor and let the user edit them. This patch does just that. This changes the behavior of "git notes add" without options when notes already exist for the given object, but I doubt that many users really depend on the previous failure from "git notes add" in this case. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/notes.c')
-rw-r--r--builtin/notes.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/builtin/notes.c b/builtin/notes.c
index a0f310b729..0d133be49b 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -527,6 +527,8 @@ static int list(int argc, const char **argv, const char *prefix)
return retval;
}
+static int append_edit(int argc, const char **argv, const char *prefix);
+
static int add(int argc, const char **argv, const char *prefix)
{
int retval = 0, force = 0;
@@ -554,14 +556,14 @@ static int add(int argc, const char **argv, const char *prefix)
};
argc = parse_options(argc, argv, prefix, options, git_notes_add_usage,
- 0);
+ PARSE_OPT_KEEP_ARGV0);
- if (1 < argc) {
+ if (2 < argc) {
error("too many parameters");
usage_with_options(git_notes_add_usage, options);
}
- object_ref = argc ? argv[0] : "HEAD";
+ object_ref = argc > 1 ? argv[1] : "HEAD";
if (get_sha1(object_ref, object))
die("Failed to resolve '%s' as a valid ref.", object_ref);
@@ -571,6 +573,18 @@ static int add(int argc, const char **argv, const char *prefix)
if (note) {
if (!force) {
+ if (!msg.given) {
+ /*
+ * Redirect to "edit" subcommand.
+ *
+ * We only end up here if none of -m/-F/-c/-C
+ * or -f are given. The original args are
+ * therefore still in argv[0-1].
+ */
+ argv[0] = "edit";
+ free_notes(t);
+ return append_edit(argc, argv, prefix);
+ }
retval = error("Cannot add notes. Found existing notes "
"for object %s. Use '-f' to overwrite "
"existing notes", sha1_to_hex(object));