]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/tag.c
tag: change misleading --list <pattern> documentation
[thirdparty/git.git] / builtin / tag.c
CommitLineData
62e09ce9
CR
1/*
2 * Builtin "git tag"
3 *
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
9#include "cache.h"
10#include "builtin.h"
11#include "refs.h"
12#include "tag.h"
13#include "run-command.h"
39686585 14#include "parse-options.h"
ffc4b801
JK
15#include "diff.h"
16#include "revision.h"
2f47eae2 17#include "gpg-interface.h"
ae7706b9 18#include "sha1-array.h"
d96e3c15 19#include "column.h"
ac4cc866 20#include "ref-filter.h"
39686585
CR
21
22static const char * const git_tag_usage[] = {
9c9b4f2f 23 N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] <tagname> [<head>]"),
c88bba18 24 N_("git tag -d <tagname>..."),
9c9b4f2f 25 N_("git tag -l [-n[<num>]] [--contains <commit>] [--points-at <object>]"
5242860f 26 "\n\t\t[--format=<format>] [--[no-]merged [<commit>]] [<pattern>...]"),
07d347cf 27 N_("git tag -v [--format=<format>] <tagname>..."),
39686585
CR
28 NULL
29};
62e09ce9 30
d96e3c15 31static unsigned int colopts;
61c2fe0c 32static int force_sign_annotate;
ae7706b9 33
df094741 34static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
ca516999 35{
ac4cc866 36 struct ref_array array;
df094741 37 char *to_free = NULL;
ca516999 38 int i;
62e09ce9 39
ac4cc866 40 memset(&array, 0, sizeof(array));
32c35cfb 41
ac4cc866
KN
42 if (filter->lines == -1)
43 filter->lines = 0;
ae7706b9 44
df094741
KN
45 if (!format) {
46 if (filter->lines) {
47 to_free = xstrfmt("%s %%(contents:lines=%d)",
17938f17 48 "%(align:15)%(refname:lstrip=2)%(end)",
df094741
KN
49 filter->lines);
50 format = to_free;
51 } else
17938f17 52 format = "%(refname:lstrip=2)";
62e09ce9
CR
53 }
54
b7cc53e9 55 verify_ref_format(format);
008ed7df 56 filter->with_commit_tag_algo = 1;
b7cc53e9
KN
57 filter_refs(&array, filter, FILTER_REFS_TAGS);
58 ref_array_sort(sorting, &array);
62e09ce9 59
b7cc53e9
KN
60 for (i = 0; i < array.nr; i++)
61 show_ref_array_item(array.items[i], format, 0);
62 ref_array_clear(&array);
63 free(to_free);
9ef176b5 64
62e09ce9
CR
65 return 0;
66}
67
e317cfaf 68typedef int (*each_tag_name_fn)(const char *name, const char *ref,
07d347cf 69 const unsigned char *sha1, const void *cb_data);
62e09ce9 70
07d347cf
LP
71static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
72 const void *cb_data)
62e09ce9
CR
73{
74 const char **p;
75 char ref[PATH_MAX];
76 int had_error = 0;
77 unsigned char sha1[20];
78
79 for (p = argv; *p; p++) {
80 if (snprintf(ref, sizeof(ref), "refs/tags/%s", *p)
81 >= sizeof(ref)) {
d08ebf99 82 error(_("tag name too long: %.*s..."), 50, *p);
62e09ce9
CR
83 had_error = 1;
84 continue;
85 }
c6893323 86 if (read_ref(ref, sha1)) {
d08ebf99 87 error(_("tag '%s' not found."), *p);
62e09ce9
CR
88 had_error = 1;
89 continue;
90 }
07d347cf 91 if (fn(*p, ref, sha1, cb_data))
62e09ce9
CR
92 had_error = 1;
93 }
94 return had_error;
95}
96
97static int delete_tag(const char *name, const char *ref,
07d347cf 98 const unsigned char *sha1, const void *cb_data)
62e09ce9 99{
755b49ae 100 if (delete_ref(NULL, ref, sha1, 0))
62e09ce9 101 return 1;
d08ebf99 102 printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(sha1, DEFAULT_ABBREV));
62e09ce9
CR
103 return 0;
104}
105
106static int verify_tag(const char *name, const char *ref,
07d347cf 107 const unsigned char *sha1, const void *cb_data)
62e09ce9 108{
07d347cf
LP
109 int flags;
110 const char *fmt_pretty = cb_data;
111 flags = GPG_VERIFY_VERBOSE;
112
113 if (fmt_pretty)
114 flags = GPG_VERIFY_OMIT_STATUS;
115
116 if (gpg_verify_tag(sha1, name, flags))
117 return -1;
118
119 if (fmt_pretty)
120 pretty_print_ref(name, sha1, fmt_pretty);
121
122 return 0;
62e09ce9
CR
123}
124
fd17f5b5 125static int do_sign(struct strbuf *buffer)
62e09ce9 126{
2f47eae2 127 return sign_buffer(buffer, buffer, get_signing_key());
62e09ce9
CR
128}
129
130static const char tag_template[] =
d78f340e 131 N_("\nWrite a message for tag:\n %s\n"
eff80a9f 132 "Lines starting with '%c' will be ignored.\n");
d3e05983
KS
133
134static const char tag_template_nocleanup[] =
d78f340e 135 N_("\nWrite a message for tag:\n %s\n"
eff80a9f
JH
136 "Lines starting with '%c' will be kept; you may remove them"
137 " yourself if you want to.\n");
62e09ce9 138
b7cc53e9
KN
139/* Parse arg given and add it the ref_sorting array */
140static int parse_sorting_string(const char *arg, struct ref_sorting **sorting_tail)
b150794d 141{
b7cc53e9
KN
142 struct ref_sorting *s;
143 int len;
b150794d 144
b7cc53e9
KN
145 s = xcalloc(1, sizeof(*s));
146 s->next = *sorting_tail;
147 *sorting_tail = s;
b150794d 148
b7cc53e9
KN
149 if (*arg == '-') {
150 s->reverse = 1;
151 arg++;
b150794d 152 }
b7cc53e9
KN
153 if (skip_prefix(arg, "version:", &arg) ||
154 skip_prefix(arg, "v:", &arg))
155 s->version = 1;
b150794d 156
b7cc53e9
KN
157 len = strlen(arg);
158 s->atom = parse_ref_filter_atom(arg, arg+len);
b150794d
JK
159
160 return 0;
161}
162
ef90d6d4 163static int git_tag_config(const char *var, const char *value, void *cb)
62e09ce9 164{
b150794d 165 int status;
b7cc53e9 166 struct ref_sorting **sorting_tail = (struct ref_sorting **)cb;
b150794d
JK
167
168 if (!strcmp(var, "tag.sort")) {
169 if (!value)
170 return config_error_nonbool(var);
b7cc53e9 171 parse_sorting_string(value, sorting_tail);
b150794d
JK
172 return 0;
173 }
174
175 status = git_gpg_config(var, value, cb);
2f47eae2
JH
176 if (status)
177 return status;
61c2fe0c
LA
178 if (!strcmp(var, "tag.forcesignannotated")) {
179 force_sign_annotate = git_config_bool(var, value);
180 return 0;
181 }
182
59556548 183 if (starts_with(var, "column."))
d96e3c15 184 return git_column_config(var, value, "tag", &colopts);
ef90d6d4 185 return git_default_config(var, value, cb);
62e09ce9
CR
186}
187
bab8118a
MH
188static void write_tag_body(int fd, const unsigned char *sha1)
189{
190 unsigned long size;
191 enum object_type type;
e10dfb62 192 char *buf, *sp;
bab8118a
MH
193
194 buf = read_sha1_file(sha1, &type, &size);
195 if (!buf)
196 return;
197 /* skip header */
198 sp = strstr(buf, "\n\n");
199
200 if (!sp || !size || type != OBJ_TAG) {
201 free(buf);
202 return;
203 }
204 sp += 2; /* skip the 2 LFs */
e10dfb62 205 write_or_die(fd, sp, parse_signature(sp, buf + size - sp));
bab8118a
MH
206
207 free(buf);
208}
209
3927bbe9
JK
210static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result)
211{
212 if (sign && do_sign(buf) < 0)
d08ebf99 213 return error(_("unable to sign the tag"));
3927bbe9 214 if (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0)
d08ebf99 215 return error(_("unable to write tag file"));
3927bbe9
JK
216 return 0;
217}
218
d3e05983
KS
219struct create_tag_options {
220 unsigned int message_given:1;
221 unsigned int sign;
222 enum {
223 CLEANUP_NONE,
224 CLEANUP_SPACE,
225 CLEANUP_ALL
226 } cleanup_mode;
227};
228
62e09ce9 229static void create_tag(const unsigned char *object, const char *tag,
d3e05983 230 struct strbuf *buf, struct create_tag_options *opt,
bd46c9a9 231 unsigned char *prev, unsigned char *result)
62e09ce9
CR
232{
233 enum object_type type;
fd17f5b5
PH
234 char header_buf[1024];
235 int header_len;
3927bbe9 236 char *path = NULL;
62e09ce9
CR
237
238 type = sha1_object_info(object, NULL);
e317cfaf 239 if (type <= OBJ_NONE)
d08ebf99 240 die(_("bad object type."));
62e09ce9
CR
241
242 header_len = snprintf(header_buf, sizeof(header_buf),
243 "object %s\n"
244 "type %s\n"
245 "tag %s\n"
246 "tagger %s\n\n",
247 sha1_to_hex(object),
248 typename(type),
249 tag,
f9bc573f 250 git_committer_info(IDENT_STRICT));
62e09ce9 251
e317cfaf 252 if (header_len > sizeof(header_buf) - 1)
d08ebf99 253 die(_("tag header too big."));
62e09ce9 254
d3e05983 255 if (!opt->message_given) {
62e09ce9
CR
256 int fd;
257
258 /* write the template message before editing: */
a4f34cbb 259 path = git_pathdup("TAG_EDITMSG");
62e09ce9
CR
260 fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
261 if (fd < 0)
d08ebf99 262 die_errno(_("could not create file '%s'"), path);
bab8118a 263
eff80a9f 264 if (!is_null_sha1(prev)) {
bab8118a 265 write_tag_body(fd, prev);
eff80a9f
JH
266 } else {
267 struct strbuf buf = STRBUF_INIT;
268 strbuf_addch(&buf, '\n');
269 if (opt->cleanup_mode == CLEANUP_ALL)
d78f340e 270 strbuf_commented_addf(&buf, _(tag_template), tag, comment_line_char);
eff80a9f 271 else
d78f340e 272 strbuf_commented_addf(&buf, _(tag_template_nocleanup), tag, comment_line_char);
eff80a9f
JH
273 write_or_die(fd, buf.buf, buf.len);
274 strbuf_release(&buf);
275 }
62e09ce9
CR
276 close(fd);
277
7198203a
SB
278 if (launch_editor(path, buf, NULL)) {
279 fprintf(stderr,
d08ebf99 280 _("Please supply the message using either -m or -F option.\n"));
7198203a
SB
281 exit(1);
282 }
62e09ce9 283 }
62e09ce9 284
d3e05983 285 if (opt->cleanup_mode != CLEANUP_NONE)
63af4a84 286 strbuf_stripspace(buf, opt->cleanup_mode == CLEANUP_ALL);
62e09ce9 287
d3e05983 288 if (!opt->message_given && !buf->len)
d08ebf99 289 die(_("no tag message?"));
62e09ce9 290
fd17f5b5 291 strbuf_insert(buf, 0, header_buf, header_len);
62e09ce9 292
d3e05983 293 if (build_tag_object(buf, opt->sign, result) < 0) {
3927bbe9 294 if (path)
d08ebf99 295 fprintf(stderr, _("The tag message has been left in %s\n"),
3927bbe9
JK
296 path);
297 exit(128);
298 }
299 if (path) {
691f1a28 300 unlink_or_warn(path);
3927bbe9
JK
301 free(path);
302 }
62e09ce9
CR
303}
304
df8512ed
CW
305static void create_reflog_msg(const unsigned char *sha1, struct strbuf *sb)
306{
307 enum object_type type;
308 struct commit *c;
309 char *buf;
310 unsigned long size;
311 int subject_len = 0;
312 const char *subject_start;
313
314 char *rla = getenv("GIT_REFLOG_ACTION");
315 if (rla) {
316 strbuf_addstr(sb, rla);
317 } else {
318 strbuf_addstr(sb, _("tag: tagging "));
319 strbuf_add_unique_abbrev(sb, sha1, DEFAULT_ABBREV);
320 }
321
322 strbuf_addstr(sb, " (");
323 type = sha1_object_info(sha1, NULL);
324 switch (type) {
325 default:
326 strbuf_addstr(sb, _("object of unknown type"));
327 break;
328 case OBJ_COMMIT:
329 if ((buf = read_sha1_file(sha1, &type, &size)) != NULL) {
330 subject_len = find_commit_subject(buf, &subject_start);
331 strbuf_insert(sb, sb->len, subject_start, subject_len);
332 } else {
333 strbuf_addstr(sb, _("commit object"));
334 }
335 free(buf);
336
337 if ((c = lookup_commit_reference(sha1)) != NULL)
338 strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
339 break;
340 case OBJ_TREE:
341 strbuf_addstr(sb, _("tree object"));
342 break;
343 case OBJ_BLOB:
344 strbuf_addstr(sb, _("blob object"));
345 break;
346 case OBJ_TAG:
347 strbuf_addstr(sb, _("other tag object"));
348 break;
349 }
350 strbuf_addch(sb, ')');
351}
352
bd46c9a9
JH
353struct msg_arg {
354 int given;
355 struct strbuf buf;
356};
357
358static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
359{
360 struct msg_arg *msg = opt->value;
361
362 if (!arg)
363 return -1;
364 if (msg->buf.len)
365 strbuf_addstr(&(msg->buf), "\n\n");
366 strbuf_addstr(&(msg->buf), arg);
367 msg->given = 1;
368 return 0;
369}
370
4f0accd6
MS
371static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
372{
373 if (name[0] == '-')
8d9c5010 374 return -1;
4f0accd6
MS
375
376 strbuf_reset(sb);
377 strbuf_addf(sb, "refs/tags/%s", name);
378
8d9c5010 379 return check_refname_format(sb->buf, 0);
4f0accd6
MS
380}
381
62e09ce9
CR
382int cmd_tag(int argc, const char **argv, const char *prefix)
383{
f285a2d7 384 struct strbuf buf = STRBUF_INIT;
4f0accd6 385 struct strbuf ref = STRBUF_INIT;
df8512ed 386 struct strbuf reflog_msg = STRBUF_INIT;
62e09ce9 387 unsigned char object[20], prev[20];
62e09ce9 388 const char *object_ref, *tag;
d3e05983
KS
389 struct create_tag_options opt;
390 char *cleanup_arg = NULL;
144c76fa 391 int create_reflog = 0;
ac4cc866 392 int annotate = 0, force = 0;
61c2fe0c 393 int cmdmode = 0, create_tag_object = 0;
dbd0f5c7 394 const char *msgfile = NULL, *keyid = NULL;
bd46c9a9 395 struct msg_arg msg = { 0, STRBUF_INIT };
e5074bfe
RS
396 struct ref_transaction *transaction;
397 struct strbuf err = STRBUF_INIT;
ac4cc866 398 struct ref_filter filter;
b7cc53e9 399 static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
df094741 400 const char *format = NULL;
3bb16a8b 401 int icase = 0;
39686585 402 struct option options[] = {
e6b722db 403 OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
ac4cc866 404 { OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
c88bba18 405 N_("print <n> lines of each tag message"),
39686585 406 PARSE_OPT_OPTARG, NULL, 1 },
e6b722db
JH
407 OPT_CMDMODE('d', "delete", &cmdmode, N_("delete tags"), 'd'),
408 OPT_CMDMODE('v', "verify", &cmdmode, N_("verify tags"), 'v'),
39686585 409
c88bba18 410 OPT_GROUP(N_("Tag creation options")),
d5d09d47 411 OPT_BOOL('a', "annotate", &annotate,
c88bba18
NTND
412 N_("annotated tag, needs a message")),
413 OPT_CALLBACK('m', "message", &msg, N_("message"),
414 N_("tag message"), parse_msg_arg),
415 OPT_FILENAME('F', "file", &msgfile, N_("read message from file")),
d5d09d47 416 OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")),
c88bba18
NTND
417 OPT_STRING(0, "cleanup", &cleanup_arg, N_("mode"),
418 N_("how to strip spaces and #comments from message")),
e703d711 419 OPT_STRING('u', "local-user", &keyid, N_("key-id"),
c88bba18
NTND
420 N_("use another key to sign the tag")),
421 OPT__FORCE(&force, N_("replace the tag if exists")),
98c32bd8 422 OPT_BOOL(0, "create-reflog", &create_reflog, N_("create a reflog")),
dd059c6c
JK
423
424 OPT_GROUP(N_("Tag listing options")),
c88bba18 425 OPT_COLUMN(0, "column", &colopts, N_("show tag list in columns")),
ac4cc866
KN
426 OPT_CONTAINS(&filter.with_commit, N_("print only tags that contain the commit")),
427 OPT_WITH(&filter.with_commit, N_("print only tags that contain the commit")),
5242860f
KN
428 OPT_MERGED(&filter, N_("print only tags that are merged")),
429 OPT_NO_MERGED(&filter, N_("print only tags that are not merged")),
b7cc53e9
KN
430 OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
431 N_("field name to sort on"), &parse_opt_ref_sorting),
32c35cfb 432 {
ac4cc866 433 OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"),
b2172fdf 434 N_("print only tags of the object"), 0, parse_opt_object_name
ae7706b9 435 },
df094741 436 OPT_STRING( 0 , "format", &format, N_("format"), N_("format to use for the output")),
3bb16a8b 437 OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
39686585
CR
438 OPT_END()
439 };
440
56b43607
KN
441 setup_ref_filter_porcelain_msg();
442
b7cc53e9 443 git_config(git_tag_config, sorting_tail);
62e09ce9 444
d3e05983 445 memset(&opt, 0, sizeof(opt));
ac4cc866
KN
446 memset(&filter, 0, sizeof(filter));
447 filter.lines = -1;
d3e05983 448
37782920 449 argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
62e09ce9 450
be15f505 451 if (keyid) {
d3e05983 452 opt.sign = 1;
2f47eae2 453 set_signing_key(keyid);
be15f505 454 }
61c2fe0c
LA
455 create_tag_object = (opt.sign || annotate || msg.given || msgfile);
456
e6b722db
JH
457 if (argc == 0 && !cmdmode)
458 cmdmode = 'l';
c1a41b9d 459
61c2fe0c 460 if ((create_tag_object || force) && (cmdmode != 0))
6fa8342b
ST
461 usage_with_options(git_tag_usage, options);
462
d96e3c15 463 finalize_colopts(&colopts, -1);
ac4cc866 464 if (cmdmode == 'l' && filter.lines != -1) {
d96e3c15
NTND
465 if (explicitly_enable_column(colopts))
466 die(_("--column and -n are incompatible"));
467 colopts = 0;
468 }
b7cc53e9
KN
469 if (!sorting)
470 sorting = ref_default_sorting();
3bb16a8b
NTND
471 sorting->ignore_case = icase;
472 filter.ignore_case = icase;
e6b722db 473 if (cmdmode == 'l') {
d96e3c15
NTND
474 int ret;
475 if (column_active(colopts)) {
476 struct column_options copts;
477 memset(&copts, 0, sizeof(copts));
478 copts.padding = 2;
479 run_column_filter(colopts, &copts);
480 }
ac4cc866 481 filter.name_patterns = argv;
df094741 482 ret = list_tags(&filter, sorting, format);
d96e3c15
NTND
483 if (column_active(colopts))
484 stop_column_filter();
485 return ret;
486 }
ac4cc866 487 if (filter.lines != -1)
d08ebf99 488 die(_("-n option is only allowed with -l."));
ac4cc866 489 if (filter.with_commit)
d08ebf99 490 die(_("--contains option is only allowed with -l."));
ac4cc866 491 if (filter.points_at.nr)
ae7706b9 492 die(_("--points-at option is only allowed with -l."));
5242860f
KN
493 if (filter.merge_commit)
494 die(_("--merged and --no-merged option are only allowed with -l"));
e6b722db 495 if (cmdmode == 'd')
07d347cf
LP
496 return for_each_tag_name(argv, delete_tag, NULL);
497 if (cmdmode == 'v') {
498 if (format)
499 verify_ref_format(format);
500 return for_each_tag_name(argv, verify_tag, format);
501 }
39686585 502
bd46c9a9
JH
503 if (msg.given || msgfile) {
504 if (msg.given && msgfile)
d08ebf99 505 die(_("only one -F or -m option is allowed."));
bd46c9a9
JH
506 if (msg.given)
507 strbuf_addbuf(&buf, &(msg.buf));
39686585
CR
508 else {
509 if (!strcmp(msgfile, "-")) {
387e7e19 510 if (strbuf_read(&buf, 0, 1024) < 0)
d08ebf99 511 die_errno(_("cannot read '%s'"), msgfile);
387e7e19 512 } else {
39686585 513 if (strbuf_read_file(&buf, msgfile, 1024) < 0)
d08ebf99 514 die_errno(_("could not open or read '%s'"),
d824cbba 515 msgfile);
62e09ce9 516 }
62e09ce9 517 }
62e09ce9
CR
518 }
519
39686585 520 tag = argv[0];
62e09ce9 521
39686585
CR
522 object_ref = argc == 2 ? argv[1] : "HEAD";
523 if (argc > 2)
d08ebf99 524 die(_("too many params"));
62e09ce9
CR
525
526 if (get_sha1(object_ref, object))
d08ebf99 527 die(_("Failed to resolve '%s' as a valid ref."), object_ref);
62e09ce9 528
4f0accd6 529 if (strbuf_check_tag_ref(&ref, tag))
d08ebf99 530 die(_("'%s' is not a valid tag name."), tag);
62e09ce9 531
c6893323 532 if (read_ref(ref.buf, prev))
62e09ce9
CR
533 hashclr(prev);
534 else if (!force)
d08ebf99 535 die(_("tag '%s' already exists"), tag);
62e09ce9 536
d3e05983
KS
537 opt.message_given = msg.given || msgfile;
538
539 if (!cleanup_arg || !strcmp(cleanup_arg, "strip"))
540 opt.cleanup_mode = CLEANUP_ALL;
541 else if (!strcmp(cleanup_arg, "verbatim"))
542 opt.cleanup_mode = CLEANUP_NONE;
543 else if (!strcmp(cleanup_arg, "whitespace"))
544 opt.cleanup_mode = CLEANUP_SPACE;
545 else
546 die(_("Invalid cleanup mode %s"), cleanup_arg);
547
df8512ed
CW
548 create_reflog_msg(object, &reflog_msg);
549
61c2fe0c
LA
550 if (create_tag_object) {
551 if (force_sign_annotate && !annotate)
552 opt.sign = 1;
d3e05983 553 create_tag(object, tag, &buf, &opt, prev, object);
61c2fe0c 554 }
62e09ce9 555
e5074bfe
RS
556 transaction = ref_transaction_begin(&err);
557 if (!transaction ||
558 ref_transaction_update(transaction, ref.buf, object, prev,
144c76fa 559 create_reflog ? REF_FORCE_CREATE_REFLOG : 0,
df8512ed 560 reflog_msg.buf, &err) ||
db7516ab 561 ref_transaction_commit(transaction, &err))
e5074bfe
RS
562 die("%s", err.buf);
563 ref_transaction_free(transaction);
3ae851e6 564 if (force && !is_null_sha1(prev) && hashcmp(prev, object))
d08ebf99 565 printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV));
62e09ce9 566
e5074bfe 567 strbuf_release(&err);
fd17f5b5 568 strbuf_release(&buf);
4f0accd6 569 strbuf_release(&ref);
df8512ed 570 strbuf_release(&reflog_msg);
62e09ce9
CR
571 return 0;
572}