Created
December 20, 2012 17:08
-
-
Save jgdavey/4346801 to your computer and use it in GitHub Desktop.
Verify a series of commits are atomic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "ERROR: You have a dirty working copy. This command would remove any files not already checked in" | |
exit 1 | |
fi | |
log() { | |
if [ -z "$quiet" ]; then | |
echo | |
if [ $# -gt 0 ]; then | |
echo $@ | |
echo | |
fi | |
fi | |
} | |
debug() { | |
if [ $verbose ]; then echo $@; fi | |
} | |
b="$(git symbolic-ref HEAD 2>/dev/null)" | |
branch="`basename $b`" | |
range="origin/${branch-master}..${branch-master}" | |
verbose= | |
quiet= | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-r|--range) range=$2; shift ;; | |
-q|--quiet) quiet=1 ;; | |
-v|--verbose) verbose=1 ;; | |
(--) shift; break ;; | |
(*) break ;; | |
esac | |
shift | |
done | |
program=$@ | |
debug "Range: $range" | |
debug "Program: $program" | |
git rev-list $range | while read rev; do | |
trap "exit 1" SIGINT SIGTERM | |
log "Running at revision $rev" | |
git checkout $rev --quiet && git clean -fd && eval $program || exit 1 | |
log | |
trap - SIGINT SIGTERM | |
done | |
git checkout $branch --quiet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment