Permalink
Browse files

Add git run command on revisions

  • Loading branch information...
1 parent a530d0d commit 9a75c3326f9d6a3e73095fa3c64f3274a2843be6 @VanTanev committed Jan 30, 2012
Showing with 65 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +64 −0 bin/run-command-on-git-revisions
View
@@ -1,5 +1,6 @@
*
+!bin/run-command-on-git-revisions
!.vimrc
!.bashrc
!.gitconfig
@@ -0,0 +1,64 @@
+#!/bin/bash
+#
+# This script runs a given command over a range of Git revisions. Note that it
+# will check past revisions out! Exercise caution if there are important
+# untracked files in your working tree.
+#
+# This came from Gary Bernhardt's dotfiles:
+# https://github.com/garybernhardt/dotfiles
+#
+# Example usage:
+# $ run-command-on-git-revisions origin/master master 'python runtests.py'
+
+set -e
+
+if [[ $1 == -v ]]; then
+ verbose=1
+ shift
+fi
+start_ref=$1
+end_ref=$2
+test_command=$3
+
+main() {
+ enforce_usage
+ run_tests
+}
+
+enforce_usage() {
+ if [ -z "$test_command" ]; then
+ usage
+ exit $E_BADARGS
+ fi
+}
+
+usage() {
+ echo "usage: `basename $0` start_ref end_ref test_command"
+}
+
+run_tests() {
+ revs=`log_command git rev-list --reverse ${start_ref}..${end_ref}`
+
+ 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
+ done
+ log_command git checkout --quiet $end_ref
+ debug "OK for all revisions!"
+}
+
+log_command() {
+ debug "=> $*"
+ eval $*
+}
+
+debug() {
+ if [ $verbose ]; then
+ echo $* >&2
+ fi
+}
+
+main
+

0 comments on commit 9a75c33

Please sign in to comment.