Skip to content

Instantly share code, notes, and snippets.

@mattfoster
Created May 12, 2017 14:12
Show Gist options
  • Save mattfoster/22248f8b7500f5bb83d882786b4def86 to your computer and use it in GitHub Desktop.
Save mattfoster/22248f8b7500f5bb83d882786b4def86 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This script runs a given command over all git tags. Note that it
# will check past revisions out! Exercise caution if there are important
# untracked files in your working tree.
#
# This is a modified version of run-command-on-git-revisions, from:
# https://github.com/garybernhardt/dotfiles
#
# Example usage:
# $ run-command-on-git-tags 'python runtests.py'
set -e
if [[ $1 == -v ]]; then
verbose=1
shift
fi
test_command=$1
main() {
enforce_usage
run_tests
}
enforce_usage() {
if [ -z "$test_command" ]; then
usage
exit 1
fi
}
run_tests() {
revs=`log_command git tag --list | tac`
for rev in $revs; do
debug "Checking out: $(git log --oneline -1 $rev)"
log_command git checkout --quiet $rev
log_command $test_command
log_command git reset --hard --quiet
done
log_command git checkout --quiet $end_ref
debug "OK for all revisions!"
}
log_command() {
debug "=> $*"
eval "$@"
}
debug() {
if [ $verbose ]; then
echo $* >&2
fi
}
usage() {
echo "usage: `basename $0` test_command"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment