Merge branch 'jh/notes-add-ui'
authorJunio C Hamano <gitster@pobox.com>
Mon, 2 May 2011 22:58:32 +0000 (15:58 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 May 2011 22:58:32 +0000 (15:58 -0700)
* jh/notes-add-ui:
  Make "git notes add" more user-friendly when there are existing notes

Conflicts:
builtin/notes.c

1  2 
builtin/notes.c

diff --cc builtin/notes.c
index d6dcfcb0149ab6dc45f4a71e21cf77d13b494e18,0d133be49b1987e8a3c6cb8d404654ed9c3328c3..8685d2bda6cbde2fb04fcc29f964c6dd6e444271
@@@ -556,29 -556,41 +558,41 @@@ static int add(int argc, const char **a
        };
  
        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");
 +              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);
 +              die(_("Failed to resolve '%s' as a valid ref."), object_ref);
  
        t = init_notes_check("add");
        note = get_note(t, object);
  
        if (note) {
                if (!force) {
 -                      retval = error("Cannot add notes. Found existing notes "
+                       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));
 +                                     "existing notes"), sha1_to_hex(object));
                        goto out;
                }
 -              fprintf(stderr, "Overwriting existing notes for object %s\n",
 +              fprintf(stderr, _("Overwriting existing notes for object %s\n"),
                        sha1_to_hex(object));
        }