Last active
December 12, 2017 19:45
-
-
Save bturrubiates/9ed129753f986c39ce9087743dc55e2a to your computer and use it in GitHub Desktop.
Script to run a command on a range of commits.
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 zsh | |
############################################################################### | |
# Script to help test whether all commits build in a pull request. | |
# Example use: | |
# | |
# git build-range c907ec08 make -C /path/to/kernel M=$PWD | |
# | |
# This will start at c907ec08 and check every commit until HEAD using the given | |
# command. | |
############################################################################### | |
if [[ "$#" -lt 2 ]]; then | |
echo "Usage: `basename $0` <Starting SHA1> <Build Command>" | |
exit 1 | |
fi | |
# Determines the currently checked out branch or commit. | |
determine-branch() { | |
ref=$(git symbolic-ref --short HEAD 2>/dev/null) | |
if [[ $? -ne 0 ]]; then | |
ref=$(git rev-parse HEAD) | |
fi | |
echo "$ref" | |
} | |
starting="$1" | |
shift | |
target=$(determine-branch) | |
rev_list=("${(@f)$(git rev-list --reverse "$starting".."$target")}") | |
echo "Processing ${#rev_list[@]} commits" | |
exit_status=0 | |
for rev in $rev_list; do | |
git checkout "$rev" >/dev/null 2>&1 | |
"$@" >/dev/null 2>&1 | |
if [[ $? -ne 0 ]]; then | |
echo "Failed to process $rev" | |
exit_status=1 | |
break | |
fi | |
echo "Successfully processed $rev" | |
done | |
git checkout "$target" | |
exit $exit_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment