diff options
author | Johan Herland <johan@herland.net> | 2010-02-13 22:28:32 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-02-13 19:36:15 -0800 |
commit | 7aa4754e552eff22d70d496dea73a9c7639d66d3 (patch) | |
tree | daad9978c75613bbec158d4dd1ea86c177e291ef /builtin-notes.c | |
parent | ba20f15e0a220705695a1ee19fb28234861b890d (diff) | |
download | git-7aa4754e552eff22d70d496dea73a9c7639d66d3.tar.gz git-7aa4754e552eff22d70d496dea73a9c7639d66d3.tar.xz |
builtin-notes: Add "add" subcommand for adding notes to objects
"git notes add" is identical to "git notes edit" except that instead of
editing existing notes for a given object, you can only add notes to an
object that currently has none. If "git notes add" finds existing notes
for the given object, the addition is aborted. However, if the new
-f/--force option is used, "git notes add" will _overwrite_ the existing
notes with the new notes contents.
If there is no existing notes for the given object. "git notes add" is
identical to "git notes edit" (i.e. it adds a new note).
The patch includes tests verifying correct behaviour of the new subcommand.
Suggested-by: Joey Hess <joey@kitenet.net>
Improved-by: Junio C Hamano <gitster@pobox.com>
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.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/builtin-notes.c b/builtin-notes.c index ec959bcb3..006edf6b1 100644 --- a/builtin-notes.c +++ b/builtin-notes.c @@ -19,6 +19,7 @@ static const char * const git_notes_usage[] = { "git notes [list [<object>]]", + "git notes add [-f] [-m <msg> | -F <file>] [<object>]", "git notes edit [-m <msg> | -F <file>] [<object>]", "git notes show [<object>]", "git notes remove [<object>]", @@ -211,7 +212,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix) const char *object_ref; char logmsg[100]; - int list = 0, edit = 0, show = 0, remove = 0, prune = 0; + int list = 0, add = 0, edit = 0, show = 0, remove = 0, prune = 0, + force = 0; int given_object; const char *msgfile = NULL; struct msg_arg msg = { 0, STRBUF_INIT }; @@ -220,6 +222,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix) OPT_CALLBACK('m', "message", &msg, "msg", "note contents as a string", parse_msg_arg), OPT_FILENAME('F', "file", &msgfile, "note contents in a file"), + OPT_BOOLEAN('f', "force", &force, "replace existing notes"), OPT_END() }; @@ -229,6 +232,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix) if (argc && !strcmp(argv[0], "list")) list = 1; + else if (argc && !strcmp(argv[0], "add")) + add = 1; else if (argc && !strcmp(argv[0], "edit")) edit = 1; else if (argc && !strcmp(argv[0], "show")) @@ -240,10 +245,10 @@ int cmd_notes(int argc, const char **argv, const char *prefix) else if (!argc) list = 1; /* Default to 'list' if no other subcommand given */ - if (list + edit + show + remove + prune != 1) + if (list + add + edit + show + remove + prune != 1) usage_with_options(git_notes_usage, options); - if ((msg.given || msgfile) && !edit) { + if ((msg.given || msgfile) && !(add || edit)) { error("cannot use -m/-F options with %s subcommand.", argv[0]); usage_with_options(git_notes_usage, options); } @@ -253,6 +258,11 @@ int cmd_notes(int argc, const char **argv, const char *prefix) usage_with_options(git_notes_usage, options); } + if (force && !add) { + error("cannot use -f option with %s subcommand.", argv[0]); + usage_with_options(git_notes_usage, options); + } + given_object = argc == 2; object_ref = given_object ? argv[1] : "HEAD"; if (argc > 2 || (prune && argc > 1)) { @@ -294,7 +304,19 @@ int cmd_notes(int argc, const char **argv, const char *prefix) return execv_git_cmd(show_args); } - /* edit/remove/prune command */ + /* add/edit/remove/prune command */ + + if (add && note) { + if (force) + fprintf(stderr, "Overwriting existing notes for object %s\n", + sha1_to_hex(object)); + else { + error("Cannot add notes. Found existing notes for object %s. " + "Use '-f' to overwrite existing notes", + sha1_to_hex(object)); + return 1; + } + } if (remove) strbuf_reset(&buf); |