t0410: make test description clearer
[git/gitster.git] / builtin / tag.c
blob93d10d59157d2ee1b41f90640bd162917f1eb162
1 /*
2 * Builtin "git tag"
4 * Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>,
5 * Carlos Rica <jasampler@gmail.com>
6 * Based on git-tag.sh and mktag.c by Linus Torvalds.
7 */
8 #define USE_THE_REPOSITORY_VARIABLE
9 #include "builtin.h"
10 #include "advice.h"
11 #include "config.h"
12 #include "editor.h"
13 #include "environment.h"
14 #include "gettext.h"
15 #include "hex.h"
16 #include "refs.h"
17 #include "object-name.h"
18 #include "object-store-ll.h"
19 #include "path.h"
20 #include "tag.h"
21 #include "parse-options.h"
22 #include "diff.h"
23 #include "revision.h"
24 #include "gpg-interface.h"
25 #include "oid-array.h"
26 #include "column.h"
27 #include "ref-filter.h"
28 #include "date.h"
29 #include "write-or-die.h"
30 #include "object-file-convert.h"
31 #include "trailer.h"
33 static const char * const git_tag_usage[] = {
34 N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] [-e]\n"
35 " [(--trailer <token>[(=|:)<value>])...]\n"
36 " <tagname> [<commit> | <object>]"),
37 N_("git tag -d <tagname>..."),
38 N_("git tag [-n[<num>]] -l [--contains <commit>] [--no-contains <commit>]\n"
39 " [--points-at <object>] [--column[=<options>] | --no-column]\n"
40 " [--create-reflog] [--sort=<key>] [--format=<format>]\n"
41 " [--merged <commit>] [--no-merged <commit>] [<pattern>...]"),
42 N_("git tag -v [--format=<format>] <tagname>..."),
43 NULL
46 static unsigned int colopts;
47 static int force_sign_annotate;
48 static int config_sign_tag = -1; /* unspecified */
50 static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting,
51 struct ref_format *format)
53 char *to_free = NULL;
55 if (filter->lines == -1)
56 filter->lines = 0;
58 if (!format->format) {
59 if (filter->lines) {
60 to_free = xstrfmt("%s %%(contents:lines=%d)",
61 "%(align:15)%(refname:lstrip=2)%(end)",
62 filter->lines);
63 format->format = to_free;
64 } else
65 format->format = "%(refname:lstrip=2)";
68 if (verify_ref_format(format))
69 die(_("unable to parse format string"));
70 filter->with_commit_tag_algo = 1;
71 filter_and_format_refs(filter, FILTER_REFS_TAGS, sorting, format);
73 free(to_free);
75 return 0;
78 typedef int (*each_tag_name_fn)(const char *name, const char *ref,
79 const struct object_id *oid, void *cb_data);
81 static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
82 void *cb_data)
84 const char **p;
85 struct strbuf ref = STRBUF_INIT;
86 int had_error = 0;
87 struct object_id oid;
89 for (p = argv; *p; p++) {
90 strbuf_reset(&ref);
91 strbuf_addf(&ref, "refs/tags/%s", *p);
92 if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &oid)) {
93 error(_("tag '%s' not found."), *p);
94 had_error = 1;
95 continue;
97 if (fn(*p, ref.buf, &oid, cb_data))
98 had_error = 1;
100 strbuf_release(&ref);
101 return had_error;
104 static int collect_tags(const char *name UNUSED, const char *ref,
105 const struct object_id *oid, void *cb_data)
107 struct string_list *ref_list = cb_data;
109 string_list_append(ref_list, ref);
110 ref_list->items[ref_list->nr - 1].util = oiddup(oid);
111 return 0;
114 static int delete_tags(const char **argv)
116 int result;
117 struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
118 struct string_list_item *item;
120 result = for_each_tag_name(argv, collect_tags, (void *)&refs_to_delete);
121 if (refs_delete_refs(get_main_ref_store(the_repository), NULL, &refs_to_delete, REF_NO_DEREF))
122 result = 1;
124 for_each_string_list_item(item, &refs_to_delete) {
125 const char *name = item->string;
126 struct object_id *oid = item->util;
127 if (!refs_ref_exists(get_main_ref_store(the_repository), name))
128 printf(_("Deleted tag '%s' (was %s)\n"),
129 item->string + 10,
130 repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV));
132 free(oid);
134 string_list_clear(&refs_to_delete, 0);
135 return result;
138 static int verify_tag(const char *name, const char *ref UNUSED,
139 const struct object_id *oid, void *cb_data)
141 int flags;
142 struct ref_format *format = cb_data;
143 flags = GPG_VERIFY_VERBOSE;
145 if (format->format)
146 flags = GPG_VERIFY_OMIT_STATUS;
148 if (gpg_verify_tag(oid, name, flags))
149 return -1;
151 if (format->format)
152 pretty_print_ref(name, oid, format);
154 return 0;
157 static int do_sign(struct strbuf *buffer, struct object_id **compat_oid,
158 struct object_id *compat_oid_buf)
160 const struct git_hash_algo *compat = the_repository->compat_hash_algo;
161 struct strbuf sig = STRBUF_INIT, compat_sig = STRBUF_INIT;
162 struct strbuf compat_buf = STRBUF_INIT;
163 char *keyid = get_signing_key();
164 int ret = -1;
166 if (sign_buffer(buffer, &sig, keyid))
167 return -1;
169 if (compat) {
170 const struct git_hash_algo *algo = the_repository->hash_algo;
172 if (convert_object_file(&compat_buf, algo, compat,
173 buffer->buf, buffer->len, OBJ_TAG, 1))
174 goto out;
175 if (sign_buffer(&compat_buf, &compat_sig, keyid))
176 goto out;
177 add_header_signature(&compat_buf, &sig, algo);
178 strbuf_addbuf(&compat_buf, &compat_sig);
179 hash_object_file(compat, compat_buf.buf, compat_buf.len,
180 OBJ_TAG, compat_oid_buf);
181 *compat_oid = compat_oid_buf;
184 if (compat_sig.len)
185 add_header_signature(buffer, &compat_sig, compat);
187 strbuf_addbuf(buffer, &sig);
188 ret = 0;
189 out:
190 strbuf_release(&sig);
191 strbuf_release(&compat_sig);
192 strbuf_release(&compat_buf);
193 free(keyid);
194 return ret;
197 static const char tag_template[] =
198 N_("\nWrite a message for tag:\n %s\n"
199 "Lines starting with '%s' will be ignored.\n");
201 static const char tag_template_nocleanup[] =
202 N_("\nWrite a message for tag:\n %s\n"
203 "Lines starting with '%s' will be kept; you may remove them"
204 " yourself if you want to.\n");
206 static int git_tag_config(const char *var, const char *value,
207 const struct config_context *ctx, void *cb)
209 if (!strcmp(var, "tag.gpgsign")) {
210 config_sign_tag = git_config_bool(var, value);
211 return 0;
214 if (!strcmp(var, "tag.sort")) {
215 if (!value)
216 return config_error_nonbool(var);
217 string_list_append(cb, value);
218 return 0;
221 if (!strcmp(var, "tag.forcesignannotated")) {
222 force_sign_annotate = git_config_bool(var, value);
223 return 0;
226 if (starts_with(var, "column."))
227 return git_column_config(var, value, "tag", &colopts);
229 if (git_color_config(var, value, cb) < 0)
230 return -1;
232 return git_default_config(var, value, ctx, cb);
235 static void write_tag_body(int fd, const struct object_id *oid)
237 unsigned long size;
238 enum object_type type;
239 char *buf, *sp, *orig;
240 struct strbuf payload = STRBUF_INIT;
241 struct strbuf signature = STRBUF_INIT;
243 orig = buf = repo_read_object_file(the_repository, oid, &type, &size);
244 if (!buf)
245 return;
246 if (parse_signature(buf, size, &payload, &signature)) {
247 buf = payload.buf;
248 size = payload.len;
250 /* skip header */
251 sp = strstr(buf, "\n\n");
253 if (!sp || !size || type != OBJ_TAG) {
254 free(buf);
255 return;
257 sp += 2; /* skip the 2 LFs */
258 write_or_die(fd, sp, buf + size - sp);
260 free(orig);
261 strbuf_release(&payload);
262 strbuf_release(&signature);
265 static int build_tag_object(struct strbuf *buf, int sign, struct object_id *result)
267 struct object_id *compat_oid = NULL, compat_oid_buf;
268 if (sign && do_sign(buf, &compat_oid, &compat_oid_buf) < 0)
269 return error(_("unable to sign the tag"));
270 if (write_object_file_flags(buf->buf, buf->len, OBJ_TAG, result,
271 compat_oid, 0) < 0)
272 return error(_("unable to write tag file"));
273 return 0;
276 struct create_tag_options {
277 unsigned int message_given:1;
278 unsigned int use_editor:1;
279 unsigned int sign;
280 enum {
281 CLEANUP_NONE,
282 CLEANUP_SPACE,
283 CLEANUP_ALL
284 } cleanup_mode;
287 static const char message_advice_nested_tag[] =
288 N_("You have created a nested tag. The object referred to by your new tag is\n"
289 "already a tag. If you meant to tag the object that it points to, use:\n"
290 "\n"
291 "\tgit tag -f %s %s^{}");
293 static void create_tag(const struct object_id *object, const char *object_ref,
294 const char *tag,
295 struct strbuf *buf, struct create_tag_options *opt,
296 struct object_id *prev, struct object_id *result,
297 struct strvec *trailer_args, char *path)
299 enum object_type type;
300 struct strbuf header = STRBUF_INIT;
301 int should_edit;
303 type = oid_object_info(the_repository, object, NULL);
304 if (type <= OBJ_NONE)
305 die(_("bad object type."));
307 if (type == OBJ_TAG)
308 advise_if_enabled(ADVICE_NESTED_TAG, _(message_advice_nested_tag),
309 tag, object_ref);
311 strbuf_addf(&header,
312 "object %s\n"
313 "type %s\n"
314 "tag %s\n"
315 "tagger %s\n\n",
316 oid_to_hex(object),
317 type_name(type),
318 tag,
319 git_committer_info(IDENT_STRICT));
321 should_edit = opt->use_editor || !opt->message_given;
322 if (should_edit || trailer_args->nr) {
323 int fd;
325 /* write the template message before editing: */
326 fd = xopen(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
328 if (opt->message_given && buf->len) {
329 strbuf_complete(buf, '\n');
330 write_or_die(fd, buf->buf, buf->len);
331 strbuf_reset(buf);
332 } else if (!is_null_oid(prev)) {
333 write_tag_body(fd, prev);
334 } else {
335 struct strbuf buf = STRBUF_INIT;
336 strbuf_addch(&buf, '\n');
337 if (opt->cleanup_mode == CLEANUP_ALL)
338 strbuf_commented_addf(&buf, comment_line_str,
339 _(tag_template), tag, comment_line_str);
340 else
341 strbuf_commented_addf(&buf, comment_line_str,
342 _(tag_template_nocleanup), tag, comment_line_str);
343 write_or_die(fd, buf.buf, buf.len);
344 strbuf_release(&buf);
346 close(fd);
348 if (trailer_args->nr && amend_file_with_trailers(path, trailer_args))
349 die(_("unable to pass trailers to --trailers"));
351 if (should_edit) {
352 if (launch_editor(path, buf, NULL)) {
353 fprintf(stderr,
354 _("Please supply the message using either -m or -F option.\n"));
355 exit(1);
357 } else if (trailer_args->nr) {
358 strbuf_reset(buf);
359 if (strbuf_read_file(buf, path, 0) < 0)
360 die_errno(_("failed to read '%s'"), path);
364 if (opt->cleanup_mode != CLEANUP_NONE)
365 strbuf_stripspace(buf,
366 opt->cleanup_mode == CLEANUP_ALL ? comment_line_str : NULL);
368 if (!opt->message_given && !buf->len)
369 die(_("no tag message?"));
371 strbuf_insert(buf, 0, header.buf, header.len);
372 strbuf_release(&header);
374 if (build_tag_object(buf, opt->sign, result) < 0) {
375 if (path)
376 fprintf(stderr, _("The tag message has been left in %s\n"),
377 path);
378 exit(128);
382 static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
384 enum object_type type;
385 struct commit *c;
386 char *buf;
387 unsigned long size;
388 int subject_len = 0;
389 const char *subject_start;
391 char *rla = getenv("GIT_REFLOG_ACTION");
392 if (rla) {
393 strbuf_addstr(sb, rla);
394 } else {
395 strbuf_addstr(sb, "tag: tagging ");
396 strbuf_add_unique_abbrev(sb, oid, DEFAULT_ABBREV);
399 strbuf_addstr(sb, " (");
400 type = oid_object_info(the_repository, oid, NULL);
401 switch (type) {
402 default:
403 strbuf_addstr(sb, "object of unknown type");
404 break;
405 case OBJ_COMMIT:
406 if ((buf = repo_read_object_file(the_repository, oid, &type, &size))) {
407 subject_len = find_commit_subject(buf, &subject_start);
408 strbuf_insert(sb, sb->len, subject_start, subject_len);
409 } else {
410 strbuf_addstr(sb, "commit object");
412 free(buf);
414 if ((c = lookup_commit_reference(the_repository, oid)))
415 strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
416 break;
417 case OBJ_TREE:
418 strbuf_addstr(sb, "tree object");
419 break;
420 case OBJ_BLOB:
421 strbuf_addstr(sb, "blob object");
422 break;
423 case OBJ_TAG:
424 strbuf_addstr(sb, "other tag object");
425 break;
427 strbuf_addch(sb, ')');
430 struct msg_arg {
431 int given;
432 struct strbuf buf;
435 static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
437 struct msg_arg *msg = opt->value;
439 BUG_ON_OPT_NEG(unset);
441 if (!arg)
442 return -1;
443 if (msg->buf.len)
444 strbuf_addstr(&(msg->buf), "\n\n");
445 strbuf_addstr(&(msg->buf), arg);
446 msg->given = 1;
447 return 0;
450 static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
452 if (name[0] == '-')
453 return -1;
455 strbuf_reset(sb);
456 strbuf_addf(sb, "refs/tags/%s", name);
458 return check_refname_format(sb->buf, 0);
461 int cmd_tag(int argc,
462 const char **argv,
463 const char *prefix,
464 struct repository *repo UNUSED)
466 struct strbuf buf = STRBUF_INIT;
467 struct strbuf ref = STRBUF_INIT;
468 struct strbuf reflog_msg = STRBUF_INIT;
469 struct object_id object, prev;
470 const char *object_ref, *tag;
471 struct create_tag_options opt;
472 char *cleanup_arg = NULL;
473 int create_reflog = 0;
474 int annotate = 0, force = 0;
475 int cmdmode = 0, create_tag_object = 0;
476 char *msgfile = NULL;
477 const char *keyid = NULL;
478 struct msg_arg msg = { .buf = STRBUF_INIT };
479 struct ref_transaction *transaction;
480 struct strbuf err = STRBUF_INIT;
481 struct ref_filter filter = REF_FILTER_INIT;
482 struct ref_sorting *sorting;
483 struct string_list sorting_options = STRING_LIST_INIT_DUP;
484 struct ref_format format = REF_FORMAT_INIT;
485 struct strvec trailer_args = STRVEC_INIT;
486 int icase = 0;
487 int edit_flag = 0;
488 struct option options[] = {
489 OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
490 { OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
491 N_("print <n> lines of each tag message"),
492 PARSE_OPT_OPTARG, NULL, 1 },
493 OPT_CMDMODE('d', "delete", &cmdmode, N_("delete tags"), 'd'),
494 OPT_CMDMODE('v', "verify", &cmdmode, N_("verify tags"), 'v'),
496 OPT_GROUP(N_("Tag creation options")),
497 OPT_BOOL('a', "annotate", &annotate,
498 N_("annotated tag, needs a message")),
499 OPT_CALLBACK_F('m', "message", &msg, N_("message"),
500 N_("tag message"), PARSE_OPT_NONEG, parse_msg_arg),
501 OPT_FILENAME('F', "file", &msgfile, N_("read message from file")),
502 OPT_PASSTHRU_ARGV(0, "trailer", &trailer_args, N_("trailer"),
503 N_("add custom trailer(s)"), PARSE_OPT_NONEG),
504 OPT_BOOL('e', "edit", &edit_flag, N_("force edit of tag message")),
505 OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")),
506 OPT_CLEANUP(&cleanup_arg),
507 OPT_STRING('u', "local-user", &keyid, N_("key-id"),
508 N_("use another key to sign the tag")),
509 OPT__FORCE(&force, N_("replace the tag if exists"), 0),
510 OPT_BOOL(0, "create-reflog", &create_reflog, N_("create a reflog")),
512 OPT_GROUP(N_("Tag listing options")),
513 OPT_COLUMN(0, "column", &colopts, N_("show tag list in columns")),
514 OPT_CONTAINS(&filter.with_commit, N_("print only tags that contain the commit")),
515 OPT_NO_CONTAINS(&filter.no_commit, N_("print only tags that don't contain the commit")),
516 OPT_WITH(&filter.with_commit, N_("print only tags that contain the commit")),
517 OPT_WITHOUT(&filter.no_commit, N_("print only tags that don't contain the commit")),
518 OPT_MERGED(&filter, N_("print only tags that are merged")),
519 OPT_NO_MERGED(&filter, N_("print only tags that are not merged")),
520 OPT_BOOL(0, "omit-empty", &format.array_opts.omit_empty,
521 N_("do not output a newline after empty formatted refs")),
522 OPT_REF_SORT(&sorting_options),
524 OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"),
525 N_("print only tags of the object"), PARSE_OPT_LASTARG_DEFAULT,
526 parse_opt_object_name, (intptr_t) "HEAD"
528 OPT_STRING( 0 , "format", &format.format, N_("format"),
529 N_("format to use for the output")),
530 OPT__COLOR(&format.use_color, N_("respect format colors")),
531 OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
532 OPT_END()
534 int ret = 0;
535 const char *only_in_list = NULL;
536 char *path = NULL;
538 setup_ref_filter_porcelain_msg();
541 * Try to set sort keys from config. If config does not set any,
542 * fall back on default (refname) sorting.
544 git_config(git_tag_config, &sorting_options);
545 if (!sorting_options.nr)
546 string_list_append(&sorting_options, "refname");
548 memset(&opt, 0, sizeof(opt));
549 filter.lines = -1;
550 opt.sign = -1;
552 argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
554 if (!cmdmode) {
555 if (argc == 0)
556 cmdmode = 'l';
557 else if (filter.with_commit || filter.no_commit ||
558 filter.reachable_from || filter.unreachable_from ||
559 filter.points_at.nr || filter.lines != -1)
560 cmdmode = 'l';
563 if (cmdmode == 'l')
564 setup_auto_pager("tag", 1);
566 if (opt.sign == -1)
567 opt.sign = cmdmode ? 0 : config_sign_tag > 0;
569 if (keyid) {
570 opt.sign = 1;
571 set_signing_key(keyid);
573 create_tag_object = (opt.sign || annotate || msg.given || msgfile ||
574 edit_flag || trailer_args.nr);
576 if ((create_tag_object || force) && (cmdmode != 0))
577 usage_with_options(git_tag_usage, options);
579 finalize_colopts(&colopts, -1);
580 if (cmdmode == 'l' && filter.lines != -1) {
581 if (explicitly_enable_column(colopts))
582 die(_("options '%s' and '%s' cannot be used together"), "--column", "-n");
583 colopts = 0;
585 sorting = ref_sorting_options(&sorting_options);
586 ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
587 filter.ignore_case = icase;
588 if (cmdmode == 'l') {
589 if (column_active(colopts)) {
590 struct column_options copts;
591 memset(&copts, 0, sizeof(copts));
592 copts.padding = 2;
593 if (run_column_filter(colopts, &copts))
594 die(_("could not start 'git column'"));
596 filter.name_patterns = argv;
597 ret = list_tags(&filter, sorting, &format);
598 if (column_active(colopts))
599 stop_column_filter();
600 goto cleanup;
602 if (filter.lines != -1)
603 only_in_list = "-n";
604 else if (filter.with_commit)
605 only_in_list = "--contains";
606 else if (filter.no_commit)
607 only_in_list = "--no-contains";
608 else if (filter.points_at.nr)
609 only_in_list = "--points-at";
610 else if (filter.reachable_from)
611 only_in_list = "--merged";
612 else if (filter.unreachable_from)
613 only_in_list = "--no-merged";
614 if (only_in_list)
615 die(_("the '%s' option is only allowed in list mode"), only_in_list);
616 if (cmdmode == 'd') {
617 ret = delete_tags(argv);
618 goto cleanup;
620 if (cmdmode == 'v') {
621 if (format.format && verify_ref_format(&format))
622 usage_with_options(git_tag_usage, options);
623 ret = for_each_tag_name(argv, verify_tag, &format);
624 goto cleanup;
627 if (msg.given || msgfile) {
628 if (msg.given && msgfile)
629 die(_("options '%s' and '%s' cannot be used together"), "-F", "-m");
630 if (msg.given)
631 strbuf_addbuf(&buf, &(msg.buf));
632 else {
633 if (!strcmp(msgfile, "-")) {
634 if (strbuf_read(&buf, 0, 1024) < 0)
635 die_errno(_("cannot read '%s'"), msgfile);
636 } else {
637 if (strbuf_read_file(&buf, msgfile, 1024) < 0)
638 die_errno(_("could not open or read '%s'"),
639 msgfile);
644 tag = argv[0];
646 object_ref = argc == 2 ? argv[1] : "HEAD";
647 if (argc > 2)
648 die(_("too many arguments"));
650 if (repo_get_oid(the_repository, object_ref, &object))
651 die(_("Failed to resolve '%s' as a valid ref."), object_ref);
653 if (strbuf_check_tag_ref(&ref, tag))
654 die(_("'%s' is not a valid tag name."), tag);
656 if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
657 oidclr(&prev, the_repository->hash_algo);
658 else if (!force)
659 die(_("tag '%s' already exists"), tag);
661 opt.message_given = msg.given || msgfile;
662 opt.use_editor = edit_flag;
664 if (!cleanup_arg || !strcmp(cleanup_arg, "strip"))
665 opt.cleanup_mode = CLEANUP_ALL;
666 else if (!strcmp(cleanup_arg, "verbatim"))
667 opt.cleanup_mode = CLEANUP_NONE;
668 else if (!strcmp(cleanup_arg, "whitespace"))
669 opt.cleanup_mode = CLEANUP_SPACE;
670 else
671 die(_("Invalid cleanup mode %s"), cleanup_arg);
673 create_reflog_msg(&object, &reflog_msg);
675 if (create_tag_object) {
676 if (force_sign_annotate && !annotate)
677 opt.sign = 1;
678 path = git_pathdup("TAG_EDITMSG");
679 create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object,
680 &trailer_args, path);
683 transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
684 &err);
685 if (!transaction ||
686 ref_transaction_update(transaction, ref.buf, &object, &prev,
687 NULL, NULL,
688 create_reflog ? REF_FORCE_CREATE_REFLOG : 0,
689 reflog_msg.buf, &err) ||
690 ref_transaction_commit(transaction, &err)) {
691 if (path)
692 fprintf(stderr,
693 _("The tag message has been left in %s\n"),
694 path);
695 die("%s", err.buf);
697 if (path) {
698 unlink_or_warn(path);
699 free(path);
701 ref_transaction_free(transaction);
702 if (force && !is_null_oid(&prev) && !oideq(&prev, &object))
703 printf(_("Updated tag '%s' (was %s)\n"), tag,
704 repo_find_unique_abbrev(the_repository, &prev, DEFAULT_ABBREV));
706 cleanup:
707 ref_sorting_release(sorting);
708 ref_filter_clear(&filter);
709 ref_format_clear(&format);
710 strbuf_release(&buf);
711 strbuf_release(&ref);
712 strbuf_release(&reflog_msg);
713 strbuf_release(&msg.buf);
714 strbuf_release(&err);
715 strvec_clear(&trailer_args);
716 free(msgfile);
717 return ret;