diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-06 14:59:43 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-06 14:59:43 +1300 |
commit | d2ec1aa9748f2e65c7037d0c16d8eea9ebdd16ed (patch) | |
tree | d3960fa2eb2ec35207229931c8dfe5bbb5ff0195 | |
parent | Merge branch 'release/v3.1.0' (diff) | |
parent | Bump VERSION (diff) | |
download | watch-vcs-tags-master.tar.gz watch-vcs-tags-master.zip |
* release/v4.0.0:
Correct subcommands for tags generation function
Remove unneeded semicolon
Correct/adjust default behaviour with no args
Refactor tag generation functions
Refactor Makefile for more generality
Add Makefile and manual page
Use correct control structure for loop body exit
Remove unused $self variable
Refactor script some more
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 17 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | watch-git-tags.1 | 13 | ||||
-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 @@ -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) @@ -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 |