Skip to content
This repository
Browse code

Add git run command on revisions

  • Loading branch information...
commit 9a75c3326f9d6a3e73095fa3c64f3274a2843be6 1 parent a530d0d
Ivan Tanev authored January 30, 2012
1  .gitignore
... ...
@@ -1,5 +1,6 @@
1 1
 *
2 2
 
  3
+!bin/run-command-on-git-revisions
3 4
 !.vimrc
4 5
 !.bashrc
5 6
 !.gitconfig
64  bin/run-command-on-git-revisions
... ...
@@ -0,0 +1,64 @@
  1
+#!/bin/bash
  2
+#
  3
+# This script runs a given command over a range of Git revisions. Note that it
  4
+# will check past revisions out! Exercise caution if there are important
  5
+# untracked files in your working tree.
  6
+#
  7
+# This came from Gary Bernhardt's dotfiles:
  8
+#     https://github.com/garybernhardt/dotfiles
  9
+#
  10
+# Example usage:
  11
+#     $ run-command-on-git-revisions origin/master master 'python runtests.py'
  12
+
  13
+set -e
  14
+
  15
+if [[ $1 == -v ]]; then
  16
+    verbose=1
  17
+    shift
  18
+fi
  19
+start_ref=$1
  20
+end_ref=$2
  21
+test_command=$3
  22
+
  23
+main() {
  24
+    enforce_usage
  25
+    run_tests
  26
+}
  27
+
  28
+enforce_usage() {
  29
+    if [ -z "$test_command" ]; then
  30
+        usage
  31
+        exit $E_BADARGS
  32
+    fi
  33
+}
  34
+
  35
+usage() {
  36
+    echo "usage: `basename $0` start_ref end_ref test_command"
  37
+}
  38
+
  39
+run_tests() {
  40
+    revs=`log_command git rev-list --reverse ${start_ref}..${end_ref}`
  41
+
  42
+    for rev in $revs; do
  43
+        debug "Checking out: $(git log --oneline -1 $rev)"
  44
+        log_command git checkout --quiet $rev
  45
+        log_command $test_command
  46
+        log_command git reset --hard
  47
+    done
  48
+    log_command git checkout --quiet $end_ref
  49
+    debug "OK for all revisions!"
  50
+}
  51
+
  52
+log_command() {
  53
+    debug "=> $*"
  54
+    eval $*
  55
+}
  56
+
  57
+debug() {
  58
+    if [ $verbose ]; then
  59
+        echo $* >&2
  60
+    fi
  61
+}
  62
+
  63
+main
  64
+

0 notes on commit 9a75c33

Please sign in to comment.
Something went wrong with that request. Please try again.