From 786702e3f1fc9aee755b539cfa633fdc061866bf Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 6 Dec 2018 14:40:33 +1300 Subject: Refactor tag generation functions --- watch-git-tags.sh | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'watch-git-tags.sh') diff --git a/watch-git-tags.sh b/watch-git-tags.sh index b9fdce8..857fbd0 100644 --- a/watch-git-tags.sh +++ b/watch-git-tags.sh @@ -1,18 +1,10 @@ -#!/bin/sh - -# List sorted local tags -tags_local() { - for repo ; do - git -C "$repo" tag --list | LC_COLLATE=C sort - done -} - -# List sorted remote tags -tags_remote() { - for repo ; do - git -C "$repo" ls-remote --quiet --refs --tags || - printf >&2 'Failed to retrieve tags for repository %s\n' "$PWD" - done | +# Function to retrieve and filter tag names +tags() { + case $1 in + remote) git -C "$repo" show-ref --tags ;; + local) git -C "$repo" ls-remote --quiet --refs --tags ;; + *) return 2 ;; + esac | while read -r _ tag ; do tag=${tag#refs/tags/} printf '%s\n' "$tag" @@ -48,8 +40,8 @@ for repo ; do ( printf '%s\n' "$repo" > path || exit # Write local and remote tags to files - tags_local "$repo" > tags/local || exit - tags_remote "$repo" > tags/remote || exit + tags local "$repo" > tags/local || exit + tags remote "$repo" > tags/remote || exit # Write new tags to file LC_COLLATE=C comm -13 -- tags/local tags/remote > tags/new -- cgit v1.2.3