tg.sh: include bad ref in ref_exists_rev failure message
[topgit/pro.git] / tg-tag.sh
blob976077a7054e6d3ced69ba9b410f9707e2a7f5a8
1 #!/bin/sh
2 # TopGit tag command
3 # Copyright (C) 2015,2017 Kyle J. McKay <mackyle@gmail.com>
4 # All rights reserved.
5 # GPLv2
7 USAGE="\
8 Usage: ${tgname:-tg} [...] tag [-s | -u <key-id>] [-f] [-q] [--no-edit] [-m <msg> | -F <file>] [--tree <treeish>] (<tagname> | --refs) [<branch>...]
9 Or: ${tgname:-tg} [...] tag (-g | --reflog) [--reflog-message | --commit-message] [--no-type] [-n <number> | -number] [<tagname>]
10 Or: ${tgname:-tg} [...] tag (--clear | --delete) <tagname>
11 Or: ${tgname:-tg} [...] tag --drop <tagname>@{n}"
13 usage()
15 if [ "${1:-0}" != 0 ]; then
16 printf '%s\n' "$USAGE" >&2
17 else
18 printf '%s\n' "$USAGE"
20 exit ${1:-0}
23 ## Parse options
25 signed=
26 keyid=
27 force=
28 msg=
29 msgfile=
30 noedit=
31 defnoedit=
32 refsonly=
33 maxcount=
34 reflog=
35 outofdateok=
36 anyrefok=
37 defbranch=HEAD
38 stash=
39 anonymous=
40 reflogmsg=
41 notype=
42 setreflogmsg=
43 quiet=0
44 noneok=
45 clear=
46 delete=
47 drop=
48 anonymous=
49 treeish=
51 is_numeric()
53 [ -n "$1" ] || return 1
54 while [ -n "$1" ]; do
55 case "$1" in
56 [0-9]*)
57 set -- "${1#?}";;
59 break;;
60 esac
61 done
62 [ -z "$1" ]
65 while [ $# -gt 0 ]; do case "$1" in
66 -h|--help)
67 usage
69 -q|--quiet)
70 quiet=$(( $quiet + 1 ))
72 --none-ok)
73 noneok=1
75 --clear)
76 clear=1
78 --delete)
79 delete=1
81 --drop)
82 drop=1
84 -g|--reflog|--walk-reflogs)
85 reflog=1
87 --reflog-message)
88 reflogmsg=1
89 setreflogmsg=1
91 --no-reflog-message|--commit-message)
92 reflogmsg=
93 setreflogmsg=1
95 --no-type)
96 notype=1
98 -s|--sign)
99 signed=1
101 -u|--local-user|--local-user=*)
102 case "$1" in --local-user=*)
103 x="$1"
104 shift
105 set -- --local-user "${x#--local-user=}" "$@"
106 esac
107 if [ $# -lt 2 ]; then
108 echo "The $1 option requires an argument" >&2
109 usage 1
111 shift
112 keyid="$1"
114 -f|--force)
115 force=1
117 --no-edit)
118 noedit=1
120 --edit)
121 noedit=0
123 --allow-outdated)
124 outofdateok=1
126 --allow-any)
127 anyrefok=1
129 --tree|--tree=*)
130 case "$1" in --tree=*)
131 x="$1"
132 shift
133 set -- --tree "${x#--tree=}" "$@"
134 esac
135 if [ $# -lt 2 ]; then
136 echo "The $1 option requires an argument" >&2
137 usage 1
139 shift
140 treeish="$(git rev-parse --quiet --verify "$1^{tree}" --)" || {
141 echo "Not a valid treeish: $1" >&2
142 exit 1
145 --refs|--refs-only)
146 refsonly=1
148 -m|--message|--message=*)
149 case "$1" in --message=*)
150 x="$1"
151 shift
152 set -- --message "${x#--message=}" "$@"
153 esac
154 if [ $# -lt 2 ]; then
155 echo "The $1 option requires an argument" >&2
156 usage 1
158 shift
159 msg="$1"
161 -F|--file|--file=*)
162 case "$1" in --file=*)
163 x="$1"
164 shift
165 set -- --file "${x#--file=}" "$@"
166 esac
167 if [ $# -lt 2 ]; then
168 echo "The $1 option requires an argument" >&2
169 usage 1
171 shift
172 msgfile="$1"
174 -n|--max-count|--max-count=*|-[1-9]*)
175 case "$1" in --max-count=*)
176 x="$1"
177 shift
178 set -- --max-count "${x#--max-count=}" "$@"
179 esac
180 case "$1" in -[1-9]*)
181 x="${1#-}"
182 shift
183 set -- -n "$x" "$@"
184 esac
185 if [ $# -lt 2 ]; then
186 echo "The $1 option requires an argument" >&2
187 usage 1
189 shift
190 maxcount="$1"
193 shift
194 break
196 --all)
197 break
199 --stash|--stash"@{"*"}")
200 if [ -n "$reflog" ]; then
201 case "$2" in -[1-9]*)
202 x1="$1"
203 x2="$2"
204 shift
205 shift
206 set -- "$x2" "$x1" "$@"
207 continue
208 esac
210 stash=1
211 defbranch=--all
212 break
214 --anonymous)
215 anonymous=1
216 defbranch=--all
217 quiet=2
218 break
220 -?*)
221 echo "Unknown option: $1" >&2
222 usage 1
225 if [ -n "$reflog" ]; then
226 case "$2" in -[1-9]*)
227 x1="$1"
228 x2="$2"
229 shift
230 shift
231 set -- "$x2" "$x1" "$@"
232 continue
233 esac
235 break
237 esac; shift; done
239 [ "$stash$anonymous" != "11" ] || usage 1
240 [ -z "$stash$anonymous" -o -n "$reflog$drop$clear$delete" ] || { outofdateok=1; force=1; defnoedit=1; }
241 [ -n "$noedit" ] || noedit="$defnoedit"
242 [ "$noedit" != "0" ] || noedit=
243 [ -z "$reflog" -o -z "$drop$clear$delete$signed$keyid$force$msg$msgfile$noedit$treeish$refsonly$outofdateok" ] || usage 1
244 [ -n "$reflog" -o -z "$setreflogmsg$notype$maxcount" ] || usage 1
245 [ -z "$drop$clear$delete" -o -z "$setreflogmsg$notype$maxcount$signed$keyid$force$msg$msgfile$noedit$treeish$refsonly$outofdateok" ] || usage 1
246 [ -z "$reflog$drop$clear$delete" -o "$reflog$drop$clear$delete" = "1" ] || usage 1
247 [ -z "$maxcount" ] || is_numeric "$maxcount" || die "invalid count: $maxcount"
248 [ -z "$maxcount" ] || [ $maxcount -gt 0 ] || die "invalid count: $maxcount"
249 [ -z "$msg" -o -z "$msgfile" ] || die "only one -F or -m option is allowed."
250 [ -z "$refsonly" ] || set -- refs..only "$@"
251 [ $# -gt 0 -o -z "$reflog" ] || set -- --stash
252 [ -n "$1" ] || { echo "Tag name required" >&2; usage 1; }
253 tagname="$1"
254 shift
255 [ "$tagname" != "--stash" ] || tagname=refs/tgstash
256 [ "$tagname" != "--anonymous" ] || tagname=TG_STASH
257 case "$tagname" in --stash"@{"*"}")
258 strip="${tagname#--stash??}"
259 strip="${strip%?}"
260 tagname="refs/tgstash@{$strip}"
261 esac
262 refname="$tagname"
263 sfx=
264 case "$refname" in [!@]*"@{"*"}")
265 sfx="$refname"
266 refname="${refname%@*}"
267 sfx="${sfx#$refname}"
268 esac
269 case "$refname" in HEAD|TG_STASH|refs/*);;*)
270 if reftest="$(git rev-parse --revs-only --symbolic-full-name "$refname" -- 2>/dev/null)" &&
271 [ -n "$reftest" ]; then
272 if [ -n "$reflog$drop$clear$delete" ]; then
273 refname="$reftest"
274 else
275 case "$reftest" in
276 refs/tags/*|refs/tgstash)
277 refname="$reftest"
280 refname="refs/tags/$refname"
281 esac
283 else
284 refname="refs/tags/$refname"
286 esac
287 refname="$refname$sfx"
288 reftype=tag
289 case "$refname" in refs/tags/*) tagname="${refname#refs/tags/}";; *) reftype=ref; tagname="$refname"; esac
290 logbase="$git_common_dir"
291 [ "$refname" != "HEAD" ] || logbase="$git_dir"
292 [ -z "$reflog$drop$clear$delete" -o $# -eq 0 ] || usage 1
293 if [ -n "$drop$clear$delete" ]; then
294 if [ -n "$sfx" ]; then
295 [ -z "$clear$delete" ] || die "invalid ref name ($sfx suffix not allowed): $refname"
296 else
297 [ -z "$drop" ] || die "invalid reflog name (@{n} suffix required): $refname"
299 old="$(git rev-parse --verify --quiet --short "${refname%$sfx}" --)" || die "no such ref: ${refname%$sfx}"
300 if [ -n "$delete" ]; then
301 git update-ref -d "$refname" || die "git update-ref -d failed"
302 printf "Deleted $reftype '%s' (was %s)\n" "$tagname" "$old"
303 exit 0
304 elif [ -n "$clear" ]; then
305 [ -f "$logbase/logs/$refname" ] || die "no reflog found for: $refname"
306 [ -s "$logbase/logs/$refname" ] || die "empty reflog found for: $refname"
307 cp -p "$logbase/logs/$refname" "$logbase/logs/$refname^-+" || die "cp failed"
308 sed -n '$p' <"$logbase/logs/$refname^-+" >"$logbase/logs/$refname" || die "reflog clear failed"
309 rm -f "$logbase/logs/$refname^-+"
310 printf "Cleared $reftype '%s' reflog to single @{0} entry\n" "$tagname"
311 exit 0
312 else
313 old="$(git rev-parse --verify --short "$refname" --)" || exit 1
314 git reflog delete --rewrite --updateref "$refname" || die "reflog drop failed"
315 printf "Dropped $reftype '%s' reflog entry (was %s)\n" "$tagname" "$old"
316 exit 0
319 if [ -n "$reflog" ]; then
320 [ "$refname" = "refs/tgstash" -o -n "$setreflogmsg" ] || reflogmsg=1
321 git rev-parse --verify --quiet "$refname" -- >/dev/null ||
322 die "no such ref: $refname"
323 [ -s "$logbase/logs/$refname" ] ||
324 die "no reflog present for $reftype: $tagname"
325 showref="$(git rev-parse --revs-only --abbrev-ref=strict "$refname" --)"
326 hashcolor=
327 resetcolor=
328 if git config --get-colorbool color.tgtag; then
329 metacolor="$(git config --get-color color.tgtag.meta)"
330 [ -n "$metacolor" ] || metacolor="$(git config --get-color color.diff.meta "bold")"
331 hashcolor="$(git config --get-color color.tgtag.commit)"
332 [ -n "$hashcolor" ] || hashcolor="$(git config --get-color color.diff.commit "yellow")"
333 datecolor="$(git config --get-color color.tgtag.date "bold blue")"
334 timecolor="$(git config --get-color color.tgtag.time "green")"
335 resetcolor="$(git config --get-color "" reset)"
337 setup_strftime
338 output()
340 sed 's/[^ ][^ ]* //' <"$logbase/logs/$refname" |
341 awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--]}' |
342 git cat-file --batch-check='%(objectname) %(objecttype) %(rest)' |
344 stashnum=-1
345 lastdate=
346 while read -r newrev type rest; do
347 stashnum=$(( $stashnum + 1 ))
348 [ "$type" != "missing" ] || continue
349 IFS="$tab" read -r cmmttr msg <<-~EOT~
350 $rest
351 ~EOT~
352 ne="${cmmttr% *}"
353 ne="${ne% *}"
354 es="${cmmttr#$ne}"
355 es="${es% *}"
356 es="${es# }"
357 obj="$(git rev-parse --verify --quiet --short "$newrev" --)"
358 extra=
359 [ "$type" = "tag" -o -n "$notype" ] ||
360 extra="$hashcolor($metacolor$type$resetcolor$hashcolor)$resetcolor "
361 if [ -z "$reflogmsg" -o -z "$msg" ]; then
362 objmsg=
363 if [ "$type" = "tag" ]; then
364 objmsg="$(git cat-file tag "$obj" |
365 sed '1,/^$/d' | sed '/^$/,$d')"
366 elif [ "$type" = "commit" ]; then
367 objmsg="$(git --no-pager log -n 1 --format='format:%s' "$obj" --)"
369 [ -z "$objmsg" ] || msg="$objmsg"
371 read newdate newtime <<-EOT
372 $(strftime "%Y-%m-%d %H:%M:%S" "$es")
374 if [ "$lastdate" != "$newdate" ]; then
375 printf '%s=== %s ===%s\n' "$datecolor" "$newdate" "$resetcolor"
376 lastdate="$newdate"
378 printf '%s %s %s%s@{%s}: %s\n' "$hashcolor$obj$reseutcolor" \
379 "$timecolor$newtime$resetcolor" \
380 "$extra" "$showref" "$stashnum" "$msg"
381 if [ -n "$maxcount" ]; then
382 maxcount=$(( $maxcount - 1 ))
383 [ $maxcount -gt 0 ] || break
385 done
388 page output
389 exit 0
391 [ -z "$signed" -o "$reftype" = "tag" ] || die "signed tags must be under refs/tags"
392 [ $# -gt 0 ] || set -- $defbranch
393 all=
394 if [ $# -eq 1 ] && [ "$1" = "--all" ]; then
395 eval set -- $(git for-each-ref --shell --format="%(refname)" "refs/$topbases")
396 outofdateok=1
397 all=1
398 if [ $# -eq 0 ]; then
399 if [ "$quiet" -gt 0 -a -n "$noneok" ]; then
400 exit 0
401 else
402 die "no TopGit branches found"
406 ensure_ident_available
407 branches=
408 allrefs=
409 extrarefs=
410 tgbranches=
411 tgcount=0
412 othercount=0
413 ignore=
414 newlist=
415 while read -r obj typ ref && [ -n "$obj" -a -n "$typ" ]; do
416 [ -n "$ref" -o "$typ" != "missing" ] || die "no such ref: ${obj%???}"
417 case " $ignore " in *" $ref "*) continue; esac
418 if [ "$typ" != "commit" -a "$typ" != "tag" ]; then
419 [ -n "$anyrefok" ] || die "not a committish (is a '$typ') ref: $ref"
420 [ "$quiet" -ge 2 ] || warn "ignoring non-committish (is a '$typ') ref: $ref"
421 ignore="${ignore:+$ignore }$ref"
422 continue
424 case " $newlist " in *" $ref "*);;*)
425 newlist="${newlist:+$newlist }$ref"
426 esac
427 if [ "$typ" = "tag" ]; then
428 [ "$quiet" -ge 2 ] || warn "storing as lightweight tag instead of 'tag' object: $ref"
429 ignore="${ignore:+$ignore }$ref"
431 done <<-EOT
433 printf '%s\n' "$@" | sed 's/^\(.*\)$/\1^{} \1/'
434 printf '%s\n' "$@" | sed 's/^\(.*\)$/\1 \1/'
436 git cat-file --batch-check='%(objectname) %(objecttype) %(rest)' 2>/dev/null ||
439 set -- $newlist
440 for b; do
441 sfn="$b"
442 [ -n "$all" ] ||
443 sfn="$(git rev-parse --revs-only --symbolic-full-name "$b" -- 2>/dev/null)" || :
444 [ -n "$sfn" ] || {
445 [ -n "$anyrefok" ] || die "no such symbolic ref name: $b"
446 fullhash="$(git rev-parse --verify --quiet "$b" --)" || die "no such ref: $b"
447 case " $extrarefs " in *" $b "*);;*)
448 [ "$quiet" -ge 2 ] || warn "including non-symbolic ref only in parents calculation: $b"
449 extrarefs="${extrarefs:+$extrarefs }$fullhash"
450 esac
451 continue
453 case "$sfn" in
454 refs/"$topbases"/*)
455 added=
456 tgish=1
457 ref_exists "refs/heads/${sfn#refs/$topbases/}" || tgish=
458 [ -n "$anyrefok" ] || [ -n "$tgish" ] || [ "$quiet" -ge 2 ] ||
459 warn "including TopGit base that's missing its head: $sfn"
460 case " $allrefs " in *" $sfn "*);;*)
461 allrefs="${allrefs:+$allrefs }$sfn"
462 esac
463 case " $branches " in *" ${sfn#refs/$topbases/} "*);;*)
464 branches="${branches:+$branches }${sfn#refs/$topbases/}"
465 added=1
466 esac
467 if [ -n "$tgish" ]; then
468 case " $allrefs " in *" refs/heads/${sfn#refs/$topbases/} "*);;*)
469 allrefs="${allrefs:+$allrefs }refs/heads/${sfn#refs/$topbases/}"
470 esac
471 case " $tgbranches " in *" ${sfn#refs/$topbases/} "*);;*)
472 tgbranches="${tgbranches:+$tgbranches }${sfn#refs/$topbases/}"
473 added=1
474 esac
475 [ -z "$added" ] || tgcount=$(( $tgcount + 1 ))
476 else
477 [ -z "$added" ] || othercount=$(( $othercount + 1 ))
480 refs/heads/*)
481 added=
482 tgish=1
483 ref_exists "refs/$topbases/${sfn#refs/heads/}" || tgish=
484 [ -n "$anyrefok" ] || [ -n "$tgish" ] ||
485 die "not a TopGit branch: ${sfn#refs/heads/} (use --allow-any option)"
486 case " $allrefs " in *" $b "*);;*)
487 allrefs="${allrefs:+$allrefs }$sfn"
488 esac
489 case " $branches " in *" ${sfn#refs/heads/} "*);;*)
490 branches="${branches:+$branches }${sfn#refs/heads/}"
491 added=1
492 esac
493 if [ -n "$tgish" ]; then
494 case " $allrefs " in *" refs/$topbases/${sfn#refs/heads/} "*);;*)
495 allrefs="${allrefs:+$allrefs }refs/$topbases/${sfn#refs/heads/}"
496 esac
497 case " $tgbranches " in *" ${sfn#refs/heads/} "*);;*)
498 tgbranches="${tgbranches:+$tgbranches }${sfn#refs/heads/}"
499 added=1
500 esac
501 [ -z "$added" ] || tgcount=$(( $tgcount + 1 ))
502 else
503 [ -z "$added" ] || othercount=$(( $othercount + 1 ))
507 [ -n "$anyrefok" ] || die "refusing to include without --allow-any: $sfn"
508 case " $allrefs " in *" $sfn "*);;*)
509 allrefs="${allrefs:+$allrefs }$sfn"
510 esac
511 case " $branches " in *" ${sfn#refs/} "*);;*)
512 branches="${branches:+$branches }${sfn#refs/}"
513 othercount=$(( $othercount + 1 ))
514 esac
516 esac
517 done
519 [ -n "$force" ] ||
520 ! git rev-parse --verify --quiet "$refname" -- >/dev/null ||
521 die "$reftype '$tagname' already exists"
523 desc="tg branch"
524 descpl="tg branches"
525 if [ $othercount -gt 0 ]; then
526 if [ $tgcount -eq 0 ]; then
527 desc="ref"
528 descpl="refs"
529 else
530 descpl="$descpl and refs"
534 get_dep() {
535 case " $seen_deps " in *" $_dep "*) return 0; esac
536 seen_deps="${seen_deps:+$seen_deps }$_dep"
537 printf 'refs/heads/%s\n' "$_dep"
538 [ -z "$_dep_is_tgish" ] || printf 'refs/%s/%s\n' "$topbases" "$_dep"
541 get_deps_internal()
543 no_remotes=1
544 recurse_deps_exclude=
545 for _b; do
546 case " $recurse_deps_exclude " in *" $_b "*) continue; esac
547 seen_deps=
548 _dep="$_b"; _dep_is_tgish=1; get_dep
549 recurse_deps get_dep "$_b"
550 recurse_deps_exclude="$recurse_deps_exclude $seen_deps"
551 done
554 get_deps()
556 get_deps_internal "$@" | sort -u
559 out_of_date=
560 if [ -n "$outofdateok" ]; then
561 if [ -n "$tgbranches" ]; then
562 while read -r dep && [ -n "$dep" ]; do
563 case " $allrefs " in *" $dep "*);;*)
564 ! ref_exists "$dep" ||
565 allrefs="${allrefs:+$allrefs }$dep"
566 esac
567 done <<-EOT
568 $(get_deps $tgbranches)
571 else
572 for b in $tgbranches; do
573 if ! needs_update "$b" >/dev/null; then
574 out_of_date=1
575 echo "branch not up-to-date: $b"
577 done
579 [ -z "$out_of_date" ] || die "all branches to be tagged must be up-to-date"
581 get_refs()
583 printf '%s\n' '-----BEGIN TOPGIT REFS-----'
585 printf '%s\n' $allrefs
586 [ -n "$outofdateok" ] || get_deps $tgbranches
587 } | sort -u | sed 's/^\(.*\)$/\1^0 \1/' |
588 git cat-file --batch-check='%(objectname) %(rest)' 2>/dev/null |
589 grep -v ' missing$' || :
590 printf '%s\n' '-----END TOPGIT REFS-----'
593 if [ -n "$refsonly" ]; then
594 get_refs
595 exit 0
598 stripcomments=
599 if [ -n "$msgfile" ]; then
600 if [ "$msgfile" = "-" ]; then
601 git stripspace >"$git_dir/TAG_EDITMSG"
602 else
603 git stripspace <"$msgfile" >"$git_dir/TAG_EDITMSG"
605 elif [ -n "$msg" ]; then
606 printf '%s\n' "$msg" | git stripspace >"$git_dir/TAG_EDITMSG"
607 else
608 case "$branches" in
609 *" "*)
610 if [ ${#branches} -le 60 ]; then
611 printf '%s\n' "tag $descpl $branches"
612 printf '%s\n' "$updmsg"
613 else
614 printf '%s\n' "tag $(( $(printf '%s' "$branches" | wc -w) )) $descpl" ""
615 for b in $branches; do
616 printf '%s\n' "$b"
617 done
621 printf '%s\n' "tag $desc $branches"
623 esac | git stripspace >"$git_dir/TAG_EDITMSG"
624 if [ -z "$noedit" ]; then
626 cat <<EOT
628 # Please enter a message for tg tag:
629 # $tagname
630 # Lines starting with '#' will be ignored.
632 # $descpl to be tagged:
635 for b in $branches; do
636 printf '%s\n' "# $b"
637 done
638 } >>"$git_dir/TAG_EDITMSG"
639 stripcomments=1
640 run_editor "$git_dir/TAG_EDITMSG" ||
641 die "there was a problem with the editor '$tg_editor'"
644 git stripspace ${stripcomments:+ --strip-comments} \
645 <"$git_dir/TAG_EDITMSG" >"$git_dir/TGTAG_FINALMSG"
646 [ -s "$git_dir/TGTAG_FINALMSG" ] || die "no tag message?"
647 echo "" >>"$git_dir/TGTAG_FINALMSG"
648 get_refs >>"$git_dir/TGTAG_FINALMSG"
650 v_count_args() { eval "$1="'$(( $# - 1 ))'; }
652 tagtarget=
653 case "$allrefs${extrarefs:+ $extrarefs}" in
654 *" "*)
655 parents="$(git merge-base --independent \
656 $(printf '%s^0 ' $allrefs $extrarefs))" ||
657 die "failed: git merge-base --independent"
660 parents="$allrefs^0"
662 esac
663 v_count_args pcnt $parents
664 if [ $pcnt -eq 1 ]; then
665 tagtarget="$parents"
666 [ -z "$treeish" ] ||
667 [ "$(git rev-parse --quiet --verify "$tagtarget^{tree}" --)" = "$treeish" ] ||
668 tagtarget=
670 if [ -z "$tagtarget" ]; then
671 tagtree="$treeish"
672 [ -n "$tagtree" ] || tagtree="$(git hash-object -t tree -w --stdin </dev/null)"
673 tagtarget="$(printf '%s\n' "tg tag branch consolidation" "" $branches |
674 git commit-tree $tagtree $(printf -- '-p %s ' $parents))"
677 init_reflog "$refname"
678 if [ "$reftype" = "tag" -a -n "$signed" ]; then
679 [ "$quiet" -eq 0 ] || exec >/dev/null
680 git tag -F "$git_dir/TGTAG_FINALMSG" ${signed:+-s} ${force:+-f} \
681 ${keyid:+-u} ${keyid} "$tagname" "$tagtarget"
682 else
683 obj="$(git rev-parse --verify --quiet "$tagtarget" --)" ||
684 die "invalid object name: $tagtarget"
685 typ="$(git cat-file -t "$tagtarget" 2>/dev/null)" ||
686 die "invalid object name: $tagtarget"
687 id="$(git var GIT_COMMITTER_IDENT 2>/dev/null)" ||
688 die "could not get GIT_COMMITTER_IDENT"
689 newtag="$({
690 printf '%s\n' "object $obj" "type $typ" "tag $tagname" \
691 "tagger $id" ""
692 cat "$git_dir/TGTAG_FINALMSG"
693 } | git mktag)" || die "git mktag failed"
694 old="$(git rev-parse --verify --short --quiet "$refname" --)" || :
695 updmsg=
696 case "$branches" in
697 *" "*)
698 if [ ${#branches} -le 100 ]; then
699 updmsg="$(printf '%s\n' "tgtag: $branches")"
700 else
701 updmsg="$(printf '%s\n' "tgtag: $(( $(printf '%s' "$branches" | wc -w) )) ${descpl#tg }")"
705 updmsg="$(printf '%s\n' "tgtag: $branches")"
707 esac
708 git update-ref -m "$updmsg" "$refname" "$newtag"
709 [ -z "$old" -o "$quiet" -gt 0 ] || printf "Updated $reftype '%s' (was %s)\n" "$tagname" "$old"
711 rm -f "$git_dir/TAG_EDITMSG" "$git_dir/TGTAG_FINALMSG"