summaryrefslogtreecommitdiff
path: root/builtin/notes.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2011-05-02 15:58:32 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2011-05-02 15:58:32 -0700
commit2d23c64ba2e91029f4ce932117a1772378d63cf3 (patch)
tree3ed1df7f43cbb310aab98f6f57e61011fe1c11c0 /builtin/notes.c
parentMerge branch 'nd/maint-setup' (diff)
parentMake "git notes add" more user-friendly when there are existing notes (diff)
downloadtgif-2d23c64ba2e91029f4ce932117a1772378d63cf3.tar.xz
Merge branch 'jh/notes-add-ui'
* jh/notes-add-ui: Make "git notes add" more user-friendly when there are existing notes Conflicts: builtin/notes.c
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 d6dcfcb014..8685d2bda6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -529,6 +529,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;
@@ -556,14 +558,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);
@@ -573,6 +575,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));