aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile17
-rw-r--r--VERSION2
-rw-r--r--watch-git-tags.113
-rw-r--r--[-rwxr-xr-x]watch-git-tags.sh (renamed from watch-git-tags)59
5 files changed, 58 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..02a5345
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+watch-git-tags
diff --git a/Makefile b/Makefile
index 90bfa3b..8801108 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,20 @@
.POSIX:
.SUFFIXES:
-.PHONY: all install clean
+.SUFFIXES: .sh
+.PHONY: all install install-bin install-man clean
PREFIX = /usr/local
-all:
-install:
+ALL = watch-git-tags
+SH = /bin/sh
+.sh:
+ { printf '#!%s\n\n' $(SH) ; cat $< ; } > $@
+ chmod +x ./$@
+all: $(ALL)
+install: install-bin install-man
+install-bin:
mkdir -p -- $(PREFIX)/bin
cp -- watch-git-tags $(PREFIX)/bin
+install-man:
+ mkdir -p -- $(PREFIX)/share/man/man1
+ cp -- watch-git-tags.1 $(PREFIX)/share/man/man1
clean:
+ rm -f -- $(ALL)
diff --git a/VERSION b/VERSION
index fd2a018..fcdb2e1 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.1.0
+4.0.0
diff --git a/watch-git-tags.1 b/watch-git-tags.1
new file mode 100644
index 0000000..70c9dc4
--- /dev/null
+++ b/watch-git-tags.1
@@ -0,0 +1,13 @@
+.TH WATCH-GIT-TAGS 1 "November 2018" "Manual page for watch-git-tags"
+.SH NAME
+.B watch-git-tags
+\- list and fetch new remote tags
+.SH SYNOPSIS
+.B watch-git-tags
+[REPO...]
+.SH DESCRIPTION
+List new remote tags for each of the named Git repositories, defaulting to the
+current directory, and then fetch them. Fetches in parallel over the repository
+list.
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
diff --git a/watch-git-tags b/watch-git-tags.sh
index e7d2c59..f8d4265 100755..100644
--- a/watch-git-tags
+++ b/watch-git-tags.sh
@@ -1,19 +1,10 @@
-#!/bin/sh
-self=watch-git-tags
-
-# List sorted local tags
-local_tags() {
- for repo ; do
- git -C "$repo" tag --list | LC_COLLATE=C sort
- done
-}
-
-# List sorted remote tags
-remote_tags() {
- 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
+ local) git -C "${2:-.}" show-ref --tags ;;
+ remote) git -C "${2:-.}" ls-remote --quiet --refs --tags ;;
+ *) return 2 ;;
+ esac |
while read -r _ tag ; do
tag=${tag#refs/tags/}
printf '%s\n' "$tag"
@@ -33,31 +24,33 @@ for sig in EXIT HUP INT TERM ; do
done
# Use current directory if no other arguments
-[ "$#" -gt 0 ] || set -- .
+if [ "$#" -eq 0 ] ; then
+ set -- "$PWD"
+fi
# Iterate through each repo in a subshell in parallel
-for repo ; do (
+for repo do (
# Make a temporary directory with a hash in its name for uniqueness
- df=$(printf %s "$repo" | sed s:/:_:g)
- cs=$(printf %s "$repo" | cksum)
- sd=$td/$df.${cs%% *}
- mkdir -- "$sd" || exit
+ name=$(printf '%s' "$repo" | sed 's:/:_:g')
+ cksum=$(printf '%s' "$repo" | cksum | sed 's:[^0-9].*::')
+ sd=$td/$name.$cksum
+ mkdir -- "$sd" "$sd"/tags || exit
# Step in and write repo path to file
cd -- "$sd" || exit
printf '%s\n' "$repo" > path || exit
# Write local and remote tags to files
- local_tags "$repo" > "$sd"/a || exit
- remote_tags "$repo" > "$sd"/b || exit
+ tags local "$repo" > tags/local || exit
+ tags remote "$repo" > tags/remote || exit
# Write new tags to file
- LC_COLLATE=C comm -13 -- [ab] > new
+ LC_COLLATE=C comm -13 -- tags/local tags/remote > tags/new
# Attempt to quietly fetch new tags so that we don't notify about the same
# ones next time
- [ -s new ] || continue
+ [ -s tags/new ] || exit
git -C "$repo" fetch --quiet --tags
) & done
@@ -67,13 +60,19 @@ wait
# Iterate through the temp dirs in order
for dir in "$td"/* ; do (
- cd -- "$dir" || exit 0
+ cd -- "$dir" || exit
# Look for non-zero "new" files (at least one new tag)
- [ -s new ] || exit 0
+ [ -s tags/new ] || exit
# Print repository path and new tags
- sed '1!s/^/\t/' -- path new
- exit 1
+ cat path
+ while read -r tag ; do
+ printf '* %s\n' "$tag"
+ done < tags/new
) ; done
+
+# Haven't yet decided on exit value semantics; for the moment, if it completes,
+# exit success
+exit 0